Õª Òª£ºÍøÂçͨÐÅÔÚµ±½ñÐÅÏ¢Éç»áÖÐÆð×Ų»¿É»òȱµÄ×÷Óà £¬ÈËÃÇ¿ÉÒÔÀûÓÃÍøÂçͨÐż¼Êõ½øÐм´Ê±µÄÐÅÏ¢½»Á÷¡£ÀýÈ磬ÈËÃÇ¿ÉÒÔͨ¹ýInternetËÑË÷ËùÒªµÄÐÅÏ¢£¬Í¨¹ýÍøÉÏͨÐŹ¤¾ßÁÄÌ죬½»Á÷ÐÅÏ¢£¬ÉÏÍø¹ºÎïµÈµÈ¡£
±¾¿ÎÌâÊÇÓ¦ÓÃÁ˼ÆËã»úÍøÂçͨÐż¼ÊõºÍJAVAÍøÂç±à³ÌµÄ»ù´¡ÖªÊ¶£¬ÒÔJAVAΪƽ̨£¬ÀûÓÃEclipse¿ª·¢¹¤¾ß£¬²¢Ê¹ÓÃSQL Server 2000¹ÜÀíÊý¾Ý¿âÊý¾Ý¿ª·¢³öµÄ»ùÓÚSocketµÄÍøÂ缴ʱͨÐÅϵͳ¡£ÏµÍ³²ÉÓÿͻ§»ú/·þÎñÆ÷£¨C/S£©µÄģʽÉè¼Æ£¬ÊÇÒ»¸öÈý²ãC/S½á¹¹£¬Êý¾Ý¿â·þÎñÆ÷¡¢Ó¦ÓóÌÐò·þÎñÆ÷¶Ë¡¢Ó¦ÓóÌÐò¿Í»§¶Ë£¬°´ÕÕ´ËÉè¼Æ˼Ï룬ϵͳ²ÉÓÃC/S½á¹¹£¬¿ÉÒÔ½«ÈÎÎñºÏÀí·ÖÅäµ½¿Í»§»ú¶ËºÍ·þÎñÆ÷¶Ë £¬´Ó¶ø½µµÍÁËϵͳµÄͨÐÅ¿ªÏú¡£´Ëϵͳ¹²·ÖΪÁ½¸öÄ£¿é£º¿Í»§¶ËÄ£¿éºÍ·þÎñÆ÷¶ËÄ£¿é¡£´Ó²Ù×÷¼ò±ã¡¢½çÃæÃÀ¹Û¡¢Áé»îʵÓõÄÓû§ÒªÇó³ö·¢£¬Éè¼Æ¿ª·¢µÄÍøÂçͨÐÅϵͳ¿ÉÒÔʵÏÖÓû§×¢²á£¬Óû§µÇ¼£¬ÏûϢͨÐźͺÃÓѹÜÀíµÈÖ÷Òª¹¦ÄÜ¡£
±¾ËµÃ÷ÊéÖ÷Òª½éÉÜÁ˱¾¿ÎÌâµÄÑо¿ÒâÒåÒÔ¼°¿ª·¢±³¾°¡¢¿ª·¢¹ý³Ì£¬ºÍËùÍê³ÉµÄ¹¦ÄÜ£¬²¢×ÅÖØ˵Ã÷ÁË¿ª·¢Éè¼ÆµÄ˼Ïë¡¢¼¼ÊõÄѵãºÍ½â¾ö·½°¸¡£
¹Ø¼ü´Ê£ºÍøÂçͨÐÅ JAVAƽ̨ C/S Socket
±ÏÒµÉè¼Æ£¨ÂÛÎÄ£©ÍâÎÄÕªÒª
The Design and Implementation of A Java-Based Internet Communication System
Abstract: Communication on Internet is very popular and crucial in people¡¯s live. Using the network communication technology, we can chat with our friends at any time. For instance, we can chat or communicate with friends and our company by some chatting tools; we even can buy everything we want on Internet.
This system is designed based on computer networking technology and some relative knowledge, using JAVA and SQL SERVER 2,000 database system as tools to develop. This implementation is based on C/S (Client/Server) model. The model can be divided into three levels: Databases level¡¢Server level¡¢Client level. According to this idea, we can distribute the task into two parts: the client and the server. The benefit is that the cost is cut down. From the needs of easy operation, beautiful and vivid interface and practical application, we can design a system which functions is including user registering, user login, adding friend, deleting friend, chatting and so on.
This paper introduces the background of the development, the functions demanded and the process of design. What¡¯s more, the paper focuses on the design principles¡¢implementation details¡¢the key techniques and the solutions.
Keywords: Web application; Java; C/S model; Socket.
Ŀ ¼
1 ÒýÑÔ 1
1.1 ¿ÎÌâµÄÑо¿ÏÖ×´ 1
1.2 ¿ÎÌâ¼ò½éÒÔ¼°Éè¼ÆÒªÇó 2
1.2.1¿ÎÌâ¼ò½é 2
1.2.2¿ÎÌâÉè¼ÆÒªÇó 2
1.3 ¿ÎÌâµÄµ÷ÑÐ 2
1.4 ¿ÉÐÐÐÔ·ÖÎö 2
1.4.1 ¿ÉÐÐÐÔ·ÖÎöµÄÄ¿µÄ 2
1.4.2 ¼¼Êõ¿ÉÐÐÐÔ·ÖÎö 3
1.4.3 ¾¼Ã¿ÉÐÐÐÔ·ÖÎö 3
1.4.4 ²Ù×÷¿ÉÐÐÐÔ·ÖÎö 3
1.4.5 ·¨ÂÉ¿ÉÐÐÐÔ·ÖÎö 4
1.5 ÂÛÎĸ÷Õ¼ò½é 4
2 ϵͳÐèÇó·ÖÎö 5
2.1 ÒµÎñÁ÷·ÖÎö 5
2.2¸ÅÄî½á¹¹Éè¼Æ 5
2.3 Êý¾ÝÁ÷·ÖÎö 5
2.4 Êý¾Ý×Öµä 6
2.4.1Êý¾Ý×Öµä 6
2.4.2´¦ÀíÂ߼˵Ã÷ 7
3 ϵͳ×ÜÌåÉè¼Æ 9
3.1 ϵͳ¿ª·¢µÄÔÔò 9
3.1.1 ÃæÏòÓû§µÄ¹Ûµã 9
3.1.2 Ñϸñ°´½×¶Î½øÐÐ 9
3.1.3 ²ÉÓÃϵͳµÄ¹Ûµã´¦Àí 9
3.1.4²ÉÓÃÄ£¿é»¯Éè¼Æ·½·¨ 9
3.1.5 Õû¸öϵͳµÄÉè¼ÆÖ÷Òª²ÉÓÿìËÙÔÐη¨ 9
3.2ϵͳ×ÜÌ幦ÄܽṹÉè¼Æ 10
3.2.1 ϵͳ´úÂëÉè¼Æ˵Ã÷ 10
3.2.2 ϵͳÉè¼Æ¼¼Êõ˵Ã÷ 10
3.2.3 ϵͳ×ÜÌ幦Äܽṹ 12
3.3 ϵͳÊý¾Ý¿âÉè¼Æ 13
3.4¿ª·¢»·¾³Éè¼ÆÓëÔËÐл·¾³Éè¼Æ 14
3.4.1 ¿ª·¢»·¾³Éè¼Æ 14
3.4.2 ÔËÐл·¾³Éè¼Æ 15
4 ·þÎñÆ÷Ä£¿éÉè¼Æ 15
4.1 Ö÷·þÎñÆ÷ÀàÉè¼Æ 15
4.2 ¶àÏß³ÌServerThreadÀàµÄÉè¼Æ 16
4.3 Óû§×¢²áÄ£¿é 17
4.4 µÇ¼Ñé֤ģ¿éÉè¼Æ 17
4.4.1µÇ¼Ïß³ÌÉè¼Æ 17
4.4.2 ֪ͨºÃÓÑÉÏÏßÄ£¿é 18
4.5 ºÃÓѹÜÀíÄ£¿é 20
4.5.1 ²éÕÒºÃÓÑÄ£¿é 20
4.5.2 ²é¿´ºÃÓÑ×ÊÁÏÄ£¿é 20
4.5.3 Ö±½ÓÌí¼ÓºÃÓÑÄ£¿é 20
4.5.4 Ìí¼ÓºÃÓÑÄ£¿é 20
4.5.5 Ìí¼ÓºÃÓÑÓ¦´ðÄ£¿é 21
4.5.6 ɾ³ýºÃÓÑÄ£¿é 21
4.6 Í˳öÏÂÏßÄ£¿é 22
5 ¿Í»§¶ËÄ£¿éÉè¼Æ 23
5.1ÐÂÓû§×¢²áÄ£¿é 23
5.1.1 ×¢²áÁ÷³Ì 23
5.1.2 ×¢²áʼþ¼àÌýÁ÷³Ì 23
5.2 Óû§µÇ¼ģ¿é 24
5.2.1 ¼àÌýµÇ¼Ê¼þ 26
5.2.2 ½çÃæÉè¼Æ 27
5.2.3 Éè¼Æ¹ý³ÌÖÐÓöµ½µÄÎÊÌâ 28
5.3 ÏûϢͨÐÅÄ£¿é 29
5.3.1 ·¢ËÍÏûÏ¢ 30
5.3.2 ¼àÌýÓû§²Ù×÷ÏûÏ¢ 32
5.3.3 ½ÓÊÕÏûÏ¢ 35
5.3.4 ·¢ËÍÎļþºÍ½ÓÊÕÎļþÄ£¿é 36
5.4 ºÃÓѹÜÀíÄ£¿é 37
5.4.1 ²éÕÒºÃÓÑ 37
5.4.2 Ìí¼ÓºÃÓÑ 38
5.4.3 ²é¿´×ÊÁÏ 39
5.4.4 ɾ³ýºÃÓÑ 39
6Óû§ÊÖ²á 40
6.1 ϵͳµÄÔËÐл·¾³ 40
6.1.1 Ó²¼þÒªÇó 40
6.1.2 Èí¼þ»·¾³ 40
6.2 ϵͳµÄ¹¦Äܼò½é 40
6.3 ϵͳµÄÔËÐкͲÙ×÷Ö¸ÄÏ 40
7 ϵͳÌØÉ«Óë²»×ã 42
7.1 ϵͳÌØÉ« 42
7.2 ϵͳ²»×ã 42
7.3 Éè¼ÆÊÕ»ñºÍÐĵà 42
½á ÂÛ 44
Ö л 45
²Î ¿¼ ÎÄ Ï× 46
1 ÒýÑÔ
1.1 ¿ÎÌâµÄÑо¿ÏÖ×´
ÍøÂçͨÐÅÔÚµ±½ñÐÅÏ¢Éç»áÖÐÆð×Ų»¿É»òȱµÄ×÷Óà £¬ÈËÃÇ¿ÉÒÔÀûÓÃÍøÂçͨÐż¼Êõ½øÐм´Ê±µÄÐÅÏ¢½»Á÷¡£±ÈÈç˵QQÁÄÌ칤¾ß£¬Ëü¾ÍÊÇÀûÓÃÍøÂçͨÐż¼Êõ¿ª·¢µÄÒ»¿îÖÚËùÖÜÖªµÄÍøÂçÁÄÌ칤¾ß¡£Ä¿Ç°£¬ÐÅÏ¢½»Á÷ÊÇ»¥ÁªÍøÌṩµÄÖ÷ÒªÄÚÈÝ£¬ÍøÂçͨÐÅϵͳÓжàÖÖʵÏÖ·½Ê½£¬ÀàËÆICQÊôÓÚÒ»ÖÖµã¶ÔµãµÄÁÄÌìϵͳ£»»¹ÓÐÒ»ÖÖÊÇ»ùÓÚSocketµÄ¼¯ÖÐʽÁÄÌìϵͳ£¬ÕâÖÖÁÄÌìϵͳÐèÒªµÇ¼ͳһµÄÁÄÌì·þÎñÆ÷¡£
µ±½ñÖ÷Á÷µÄÁÄÌ칤¾ßÓÐQQ£¬ICQ£¬MSN Messenger£¬Yahoo MessengerµÈ£¬¹úÄÚ×îÈÈÃŵĵ±ÊôQQ£¬ÌÚѶQQ£¨OICQ£©ÊÇÓÉÉîÛÚÊÐÌÚѶ¼ÆËã»úϵͳ¹«Ë¾¿ª·¢µÄ£¬»ùÓÚInternetµÄ¼´Ê±Ñ°ºôÈí¼þ¡£Äú¿ÉÒÔʹÓÃQQºÍºÃÓÑÓû§½øÐн»Á÷£¬ÐÅÏ¢¼´Ê±·¢ËÍ£¬¼´Ê±»Ø¸´£¬ÊÕ·¢¼°Ê±¡¢¹¦ÄÜÈ«Ãæ¡£´ËÍâQQ»¹¾ßÓÐBP»úÍøÉÏÑ°ºô¡¢ÁÄÌìÊÒ¡¢´«ÊäÎļþ¡¢ÓïÒôÓʼþ¡¢ÊÖ»ú¶ÌѶ·þÎñµÈ¹¦ÄÜ£¬QQ²»½ö½öÊÇÐéÄâµÄÍøÂçÑ°ºô»ú£¬¸ü¿ÉÓ봫ͳµÄÎÞÏßÑ°ºôÍø¡¢GSMÒƶ¯µç»°µÄ¶ÌÏûϢϵͳ»¥Áª£¬Ä¿Ç°QQºÍÈ«¹ú¶à¼ÒÑ°ºǫ̂¡¢Òƶ¯Í¨ÐŹ«Ë¾ÓÐÒµÎñºÏ×÷¡£ÊǹúÄÚ²»¿É¶àµÃµÄÖÐÎÄÍøÂçÑ°ºô»ú¡£QQÖ§³ÖÏÔʾÅóÓÑÔÚÏßÐÅÏ¢¡¢¼´Ê±´«ËÍÐÅÏ¢¡¢¼´Ê±½»Ì¸¡¢¼´Ê±·¢ËÍÎļþºÍÍøÖ·¡£QQ¿ÉÒÔÔÚÖÐÎÄWin95/98/NT/2000²Ù×÷ϵͳÏÂÔËÐУ¬ÊÇÊ®·ÖÁé»îµÄÍøÂçÑ°ºô¹¤¾ß¡£Ëü»á×Ô¶¯¼ì²éÄúÊÇ·ñÒÑÁªÍø£¬Èç¹ûÄúµÄµçÄÔÒÑÁ¬ÈëInternet£¬¿ÉÒÔËÑË÷ÍøÓÑ¡¢ÏÔʾÔÚÏßÍøÓÑ£¬¿ÉÒÔ¸ù¾ÝQQºÅ¡¢êdzơ¢ÐÕÃû¡¢emailµØÖ·µÈ¹Ø¼ü´ÊÀ´²éÕÒ£¬ÕÒµ½ºó¿É¼ÓÈ뵽ͨѶ¼ÖС£µ±ÄúµÄͨѶ¼ÖеÄÍøÓÑÔÚÏßʱ£¬QQÖÐÅóÓѵÄÍ·Ïñ¾Í»áÏÔʾÔÚÏߣ¬¸ù¾ÝÌáʾ¾Í¿ÉÒÔ·¢ËÍÐÅÏ¢£¬Èç¹û¶Ô·½µÇ¼ÇÁËÑ°ºô»ú»ò¿ªÍ¨ÁËGSMÊÖ»ú¶ÌÏûÏ¢£¬¼´Ê¹ÀëÏßÁË£¬ÄúÒ²¿É¼°Ê±½«ÐÅÏ¢´«µÝ¸øÄúµÄºÃÓÑ¡£