`
`.
`
`. . . . . . . . • •
`
`Complete source
`code and design to
`, · create your own
`IM applications
`
`Dream tech
`Software Team
`
`
`
`Instant Messaging Systems: Cracking the Code™
`
`Published by
`Wiley Publishing, Inc.
`605 Third A venue
`NewYork,NY 10158
`www.wiley.com
`
`This book is printed on acid-free paper.@)
`
`Copyright © 2002 by Wiley Publishing, Inc. All rights reserved.
`
`Published by Wiley Publishing, Inc.
`
`No part of this publication may be reproduced, stored in a retrieval system or transmitted in any
`form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise,
`except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without
`either the prior written permission of the Publisher, or authorization through payment of the
`appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA
`01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should be
`addressed to the Permissions Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd.,
`Indianapolis, IN 46256, (317) 572-3447, Fax: (317) 572-4447, E-Mail:
`permcoordinator@wiley.com.This publication is designed to provide accurate and authoritative
`information in regard to the subject matter covered. It is sold with the understanding that the
`publisher is not engaged in professional services. If professional advice or other expert assistance
`is required, the services of a competent professional person should be sought.
`
`Wiley, the Wiley Publishing logo, and Cracking the Code are trademarks or registered trademarks
`of Wiley Publishing, Inc., in the United States and other countries, and may not be used without
`written permission. All other trademarks are the property of their respective owners. Wiley
`Publishing, Inc., is not associated with any product or vendor mentioned in this book.
`
`Library of Congress Control Number: 2002106774
`
`ISBN: 0-7645-4953-7
`
`Printed in the United States of America.
`
`10 9 8 7 6 5 4 3 2 1
`
`lB/QW /QU/QS/IN
`
`
`
`r
`
`Contents
`
`Preface ............................................................................................................ vii
`Acknowledgments .... ~ ............................................................ o••························xi
`Chapter 1: Introduction to Instant Messaging .............................................. 1
`A Brief History of Instant Messaging ........................................................................................ 1
`The Advantages of Instant Messaging ....................................................................................... 2
`The Need for Instant Messaging ................................................................................................ 2
`The Future of Instant Messaging ............................................................................................... 3
`Jabber Instant Messaging Model ............................................................................................... 3
`Introduction to the Instant Messaging Application .................................................................... 7
`Required Programtning Techniques ........................................................................................ 10
`Sumtnary .................................................................................................................................. 14
`Chapter 2: Designing the Instant Messaging Application .......................... 15
`Application Design Considerations ......................................................................................... 15
`Database Design Considerations .............................................................................................. 16
`Server Module Design Considerations .................................................................................... 16
`Client Module Design Considerations ..................................................................................... 36
`Application Comtnunication Standards ................................................................................... 40
`Issues Involved in Creating the Session ......................... · .......................................................... 45
`Issues Involved in Closing the Stream ..................................................................................... 46
`Sumtnary .................................................................................................................................. 4 7
`Chapter 3: Instant Messaging Server (Java) .............................................. .48
`Java Web Services ................................................................................................................... 48
`Server Development ................................................................................................................ 56
`Inside the Server Application .................................................................................................. 63
`Inside Java Web Services ........................................................................................................ 91
`
`
`
`Technical Documentation ...................................................................................................... 100
`Summary ................................................................................................................................ 211
`Chapter 4: Instant Messaging Server (C#) ................................................ 212
`Web Services ......................................................................................................................... 212
`Developing the Server ............................................................................................................ 217
`Inside the Server Application ................................................................................................. 222
`Inside a Web Service ............................................................................................................. 23 7
`Technical Documentation ...................................................................................................... 242
`Summary ................................................................................................................................ 333
`Chapter 5: The Instant Messaging Client (Java) ...................................... 334
`Basic Implementation of the Client ....................................................................................... 335
`Establishing a Connection with the Local Server .................................................................. 339
`Programming Client Requests ............................................................................................... 341
`Handling Responses ............................................................................................................... 357
`Technical Documentation ...................................................................................................... 371
`Summary ................................................................................................................................ 493
`Chapter 6: Instant Messaging Client (C#) ................................................. 494
`Client Module Tasks .............................................................................................................. 494
`Server Responses ................................................................................................................... 508
`Technical Documentation ...................................................................................................... 519
`Summary ................................................................................................................................ 623
`Chapter 7: Enhancing Instant Messaging .................................................. 624
`Introduction to J2ME ............................................................................................................. 624
`Design Techniques ................................................................................................................. 632
`Programming Client Requests ............................................................................................... 645
`Handling Responses ............................................................................................................... 650
`Summary ................................................................................................................................ 655
`Appendix A: What's on the CD-ROM ....................................................... 657
`
`Appendix B: Instant Messaging Software Resources ............................... 667
`
`Index .............................................................................................................. 669
`
`Sun Microsystems, Inc. Binary Code License Agreement ........................ 685
`
`
`
`Wiley Publishing, Inc. End-User License Agreement ............................... 702
`
`Important CD-ROM Information ............................................................... 704
`
`
`
`Chapter 1
`Introduction to
`Instant essaging
`
`Instant messaging (IM) is an Internet-based protocol application that allows one-to-one
`communication between users employing a variety of devices. The most popular form ofIM is
`chatting, where short, text-based messages are exchanged among computers. With the advent
`of technologies such as Wireless Application Protocol (W AP) and the popularity of handheld
`devices such as mobile phones, Short Message Service (SMS) added a new dimension to
`instant messaging integration.
`
`SMS refers to sending and receiving text messages to and from mobile telephones. The text
`may be composed of words or numbers or may be an alphanumeric combination. SMS was
`created as part of the GSM Phase 1 standard. We think the first short message was sent in
`December 1992 from a PC to a mobile phone on the Vodafone GSM network in the U.K. Each
`short message ranges between 70 □ 160 characters.SMS has a store-forward capability; this
`means sending messages is possible even when the recipient is not available. The user is
`notified when a message is waiting, as with voicemail.
`
`Integration of SMS and instant messaging allows you to deliver short messages by using the
`instant messaging facility over handheld devices. Today, instant messaging can be availed free
`of cost. Software giants such as Yahoo!, Microsoft, and AOL are already offering free instant
`messaging facilities.
`
`A Brief History of Instant Messaging
`Instant Messaging has been around for more than two decades. The first major player to enter
`the arena oflnstant Messaging was AOL, which launched its own version of instant messenger
`with a component used for managing all the incoming and outgoing messages and the list of
`friends. This component is popularly known as buddy list. Soon, Microsoft and Yahoo!
`followed AOL's trail. As a result, MSN and Yahoo! messenger appeared on the market with a
`variety of impressive new services. In its early days, instant messaging uses were restricted to
`splashing messages on bulletin boards. Gradually, instant messaging became a major area of
`interest for youngsters. Society acknowledges instant messaging as the most common means
`by which people of varying age groups, especially youngsters, communicate with one another.
`
`