ÄãºÃ£¬»¶Ó­À´µ½¾­¹ÜÖ®¼Ò [µÇ¼] [×¢²á]

ÉèΪÊ×Ò³ | ¾­¹ÜÖ®¼ÒÊ×Ò³ | Êղر¾Õ¾

»ùÓÚTCPIPЭÒé½øÐÐÈô¸É³ÌÐòÄ£¿é¿ª·¢_¼ÆËã»úרҵÂÛÎÄ

·¢²¼Ê±¼ä£º2015-01-16 À´Ô´£ºÈË´ó¾­¼ÃÂÛ̳
¼ÆËã»úרҵÂÛÎÄ·¶ÎÄ ÕªÒª ±¾¿ÎÌâ½éÉÜÔÚUnix»·¾³Ï»ùÓÚTCP/IPЭÒé½øÐÐÈô¸É³ÌÐòÄ£¿é¿ª·¢£¬¹¹Ôìµã¶ÔµãÄ£ÐÍ¡£ ±¾¿ÎÌâÓÉÒ»¸ö¿Í»§¶Ë£¬Ò»¸ö·þÎñÆ÷£¬Ò»¸ö´«Êä·þÎñÆ÷¹¹³É¡£¿Í»§¶ËÏò·þÎñÆ÷·¢ËÍÏÂÔØÇëÇ󣬷þÎñÆ÷²éѯÊý¾Ý¿â²¢·µ»ØÏà¹Ø´«Êä·þÎñÆ÷µÄµØÖ·ÐÅÏ¢¡£¿Í»§¶Ë¸ù¾Ý·þÎñÆ÷·µ»ØµÄµØÖ·Óë´«Êä·þÎñÆ÷Á¬½Ó½øÐÐÊý¾ÝÏÂÔØ¡£·þÎñÆ÷Íê³ÉÐÅÏ¢µÄÊÕ¼¯£¬²éѯºÍ״̬¿ØÖƵŦÄÜ£¬ÆäËüµÄ´¦Àí¹¦ÄÜÒÀÀµ¿Í»§¶ËÓë´«Êä·þÎñÆ÷¡£ÕâÀï·þÎñÆ÷ÆðµÄÊÇÒ»¸öÇÅÁº×÷Ó㬲¢²»ÊÇÐÅÏ¢µÄÖ÷ÒªÔØÌå¡£±¾¿ÎÌâÖ÷ÒªµÄÓÃ;ÊÇ×ÊÁϵÄÊÕ¼¯´«²¥¡£ ÔÚÒ»¸ö³ÉÊìµÄÍøÂçÖÐÓгÉǧÉÏÍò¸ö¿Í»§¶ËºÍ´«Êä·þÎñÆ÷£¬±¾¿ÎÌâÖصãÑо¿ÔÚUnix»·¾³ÏÂÈçºÎÀûÓÃsocket£¨Ì×½Ó×Ö£©Íê³É³ÌÐò¼äµÄͨÐÅ¡£ÖÁÓÚÖмäµÄÐÅÏ¢ÊÕ¼¯¡¢×´Ì¬²éѯ¿ØÖƹý³ÌµÈÒÔ¾ßÓÐÀàËƹ¦ÄܵijÌÐò´úÌæʵÏÖ¡£ ¹Ø¼ü´Ê: ¼ÆËã»úͨÐÅ£¬Unix£¬Socket, ЭÒé Abstract Under Unix circumstance, this subject inroduce the exploitation of TCP/IP developing several procedure modules, Construction peer-to-peer model. The design is constituted by a client ,a server and a transfer server. Client send download request to the server.The server inquiries the database then return the address information of related transfer server . Client server connects to the transfer server based on the return address information for data downloadding . Server control client connectting to transfer server then to sent data and piece them together and so on. The server here is the role of a bridge.It is not the main carrier of the data . Server complete collectting information, inquiring and state control function. Other treatment relies mostly on the client and transfer server themselves. It¡¯s fully embodies the subject that the mainstay of the network is the client not server. The main issue is the use of the information collection and dissemination in the subject. There are thousands of clients and transfer servers at least in a mature network.This paper only focus on how to use socket to communicate between the programs in Unix environment. As for the middle of information gathering, state inquiries and control process replaced by some simple procedures to achieve similar functions.. Keyword: Computer communications, Unix, Socket, Protocol Ŀ¼ ÕªÒªI AbstractII µÚ1Õ Ð÷ÂÛ1 µÚ2Õ unixϵͳ»ù´¡3 2.1 unixϵͳ¸ÅÊö3 2.1.1 unixϵͳµÄÀúÊ·3 2.1.2 unixϵͳµÄÌصã5 2.1.3 unixϵͳµÄÌåϵ½á¹¹7 2.1.4 unixϵͳµÄµØÖ·¿Õ¼ä7 2.2 unix³£ÓõÄÍøÂçÃüÁî8 2.3 unixÏÂÈí¼þ¿ª·¢»·¾³11 2.3.1 vi±à¼­¼ò½é11 2.3.2 gcc±àÒëÆ÷¼ò½é14 µÚ3Õ TCP/IP¼ò½é16 3.1 TCP/IPÌåϵ16 3.2 TCPЭÒé16 3.2.1½¨Á¢TCPÁ¬½Ó16 3.2.2 TCPÁ¬½Ó¹Ø±Õ¹ý³ÌÈçÏÂ17 3.2.3 TCP°ü½á¹¹17 3.3 UDPЭÒé17 3.5 ICMPЭÒé18 3.6 ¶Ë¿Ú·ÖÅä18 3.6.1¶Ë¿Ú½éÉÜ18 3.6.2 ¶Ë¿Ú·ÖÀà19 µÚ4Õ Ì×½Ó×Ö»ù´¡20 4.1.¸ÅÊö20 4.2 Ì×½Ó×ÖÀàÐÍ20 4.3Ì×½Ó×ÖµØÖ·½á¹¹21 4.3.1 sockaddr µØÖ·½á¹¹21 4.3.2 INETЭÒé´ØµØÖ·½á¹¹Sockaddr_in21 4.3.3¡¡in_addrµØÖ·½á¹¹22 µÚ5Õ TCPÌ×½Ó×Ö23 5.1 TCPÌ×½Ó×ÖµÄʵÏÖ¹ý³Ì23 5.1.1 ·þÎñÆ÷¶Ë²½Öè23 5.1.2 ¿Í»§¶Ë²½Öè23 5.1.3 ͼʾ24 5.2 SOCKETº¯Êý½éÉÜ24 µÚ6Õ¡¡»ùÓÚTCP/IPµÄsocketÍøÂçͨÐųÌÐòʵÏÖ27 6.1»ù±¾¿ò¼Ü27 6.2³ÌÐòÁ÷³Ì27 6.2.1¿Í»§¶Ë27 6.2.2·þÎñÆ÷¶Ë28 6.2.3 ´«Êä·þÎñÆ÷29 6.2.4¸÷½ø³Ì¼äͨÐÅͼʾ29 6.3 ¿Í»§¶ËÆô¶¯30 6.4·þÎñÆ÷µÄ±íά»¤31 6.5Êý¾Ý´«Êä¹ý³Ì33 6.6Êý¾ÝÆ´½Ó34 6.7 µ÷ÊÔ35 6.7.1 µ÷ÊÔ»·¾³¹¹½¨35 6.7.2 µ÷ÊÔÕýȷʱ½á¹û36 µÚ7Õ¡¡½áÂÛ37 ÖÂл38 ²Î¿¼ÎÄÏ×39 ¸½Â¼¡¡³ÌÐòÔ´´úÂë40 ¸½Â¼1 ¿Í»§¶Ë³ÌÐò´úÂë40 ¸½Â¼2¡¡·þÎñÆ÷¶Ë³ÌÐò´úÂë46 ¸½Â¼3¡¡´«Êä·þÎñÆ÷¶Ë´úÂë50
¾­¹ÜÖ®¼Ò¡°Ñ§µÀ»á¡±Ð¡³ÌÐò
  • ɨÂë¼ÓÈë¡°¿¼ÑÐѧϰ±Ê¼ÇȺ¡±
ÍƼöÔĶÁ
¾­¼ÃѧÏà¹ØÎÄÕÂ
±êÇ©ÔÆ
¾­¹ÜÖ®¼Ò¾«²ÊÎÄÕÂÍƼö