1 / 36

Socket Programming

Socket Programming. Present: KS Wu. Outline. UDP client/server communication Introduction of socket functions How MSN Messenger works. Outline. UDP client/server communication Introduction of socket functions How MSN Messenger works. UDP Server. Socket functions for UDP client-server.

kolya
Télécharger la présentation

Socket Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Socket Programming Present: KS Wu

  2. Outline • UDP client/server communication • Introduction of socket functions • How MSN Messenger works NTUEECS COBRA LAB

  3. Outline • UDP client/server communication • Introduction of socket functions • How MSN Messenger works NTUEECS COBRA LAB

  4. UDP Server Socket functions for UDP client-server socket() bind() UDP Client socket() recvfrom() Wait for a request from client sendto() Process request sendto() recvfrom() close() NTUEECS COBRA LAB

  5. Outline • UDP client/server communication • Introduction of socket functions • How MSN Messenger works NTUEECS COBRA LAB

  6. Socket functions • WSAStartup( ) • socket( ) • bind( ) • sendto( ) • recvfrom( ) • closesocket( ) NTUEECS COBRA LAB

  7. WSAStartup Function WSADATA wsadata; WSAStartup(0x101, (LPWSADATA) &wsadata) version: 1.1 NTUEECS COBRA LAB

  8. socket Function int socket( int af, int type, int protocol ); Returns: nonnegative descriptor if OK, negative number on error NTUEECS COBRA LAB

  9. Parameters NTUEECS COBRA LAB

  10. bind Function int bind( SOCKET sockfd, const struct sockaddr* name, int namelen ); Returns: 0 if OK, negative number on error NTUEECS COBRA LAB

  11. Parameters • sockfd • Descriptor identifying an unbound socket. (returned by the socket function.) • name • A pointer to a protocol-specific address • namelen • Length of the value in the name parameter, in bytes. NTUEECS COBRA LAB

  12. sendto Function int sendto( SOCKET sockfd, const char* buf, int len, int flags, const struct sockaddr* to, int tolen ); Returns: # of bytes sent (< len) if OK, negative number on error NTUEECS COBRA LAB

  13. Parameters • sockfd • Descriptor identifying a bound socket. • buf • Buffer containing the data to be transmitted. • len • Length of the data in buf, in bytes. NTUEECS COBRA LAB

  14. Parameters (cont.) • flags • Indicator specifying the way in which the call is made. (usually set to 0) • to • Optional pointer to a sockaddr structure that contains the address of the target socket. • tolen • Size of the address in to, in bytes. NTUEECS COBRA LAB

  15. recvfrom Function int recvfrom( SOCKET sockfd, char* buf, int len, int flags, struct sockaddr* from, int* fromlen ); Returns: # of bytes received (< len) if OK, 0 if connection has been gracefully closed, negative number on error NTUEECS COBRA LAB

  16. Parameters • sockfd • Descriptor identifying a bound socket. • buf • Buffer for the incoming data. • len • Length of the data in buf, in bytes. NTUEECS COBRA LAB

  17. Parameters (cont.) • flags • Indicator specifying the way in which the call is made. (usually set to 0) • from • Optional pointer to a buffer in a sockaddr structure that will hold the source address upon return. • fromlen • Optional pointer to the size, in bytes, of the from buffer. NTUEECS COBRA LAB

  18. closesocket Function int closesocket( SOCKET sockfd ); Returns: 0 if OK, negative number on error NTUEECS COBRA LAB

  19. Parameters • sockfd • Descriptor identifying the socket to close. NTUEECS COBRA LAB

  20. Outline • UDP client/server communication • Introduction of socket functions • How MSN Messenger works NTUEECS COBRA LAB

  21. How MSN Messenger works • 2 phases • Authentication Phase • Instant Messaging Phase NTUEECS COBRA LAB

  22. How MSN Messenger works (cont.) • Authentication Phase • logging into the MSN messenger server • Retrieve the friend list • Instant Messaging Phase • Session-based • sending/accepting requests for an Instant Messaging session • sending/receiving messages NTUEECS COBRA LAB

  23. Authentication Phase • Protocol versioning • Server policy information • Authentication • Referral • Client user property synchronization • List retrieval and property management • Client states • List modifications • Notification messages • Connection closed NTUEECS COBRA LAB

  24. Instant Messaging Phase • Referral to switchboard • Switchboard connections and authentication • Inviting users to a switchboard session • Session participant changes • Leaving a switchboard session • Instant messages • Receiving an instant message NTUEECS COBRA LAB

  25. Server Components • Dispatch server • Notification server • Switchboard server NTUEECS COBRA LAB

  26. Dispatch server • protocol version negotiation • determination of which NS is associated with the client making a connection • referring the client to the proper NS NTUEECS COBRA LAB

  27. Notification server • authenticate, synchronize user properties • exchange asynchronous event notifications NTUEECS COBRA LAB

  28. Switchboard server • provide instant messaging sessions NTUEECS COBRA LAB

  29. Client Scenario 2.Server policy information 1.Protocol Versioning DS 3.Authentication TCP (port 1863) SP (MD5) version Policy? Initiate info Passwd + challenge userID + nickname Challenge info NTUEECS COBRA LAB

  30. Yes No, update! Client Scenario DS 6.List Retrieval And Property Management 5.Client User Property Synchronization 4.Referral NS NS addr:port Latest properties? (cache) List? List aa@aaa.com nickname b@bbb.com nickname … Log in NTUEECS COBRA LAB

  31. Online Offline Invisible State Client Scenario 8.List Modifications 7.Client States NS ADD/REM xx@xxx.com nickname OK! (new SN) OK! NTUEECS COBRA LAB

  32. Client Scenario Inviting Users to a Switchboard Session Switchboard Connections and Authentication Referral to Switchboard NS SS Session ID OK! SS? SS addr SP (CHI) cookie userID cookie called userID NTUEECS COBRA LAB

  33. Client Scenario Getting Invited to a Switchboard Session Session Participant Changes Leaving a Switchboard Session NS SS Left! JOIN! index # of participants SessionID SS addr SP Cookie callerID nickname New userID nickname Left userID Bye! userID cookie sessionID NTUEECS COBRA LAB

  34. Client Scenario Sending a instant message Receiving an Instant Message NS SS Msg Msg NTUEECS COBRA LAB

  35. Reference • “Unix Network Programming” • “WinSock 網路程式設計之鑰” • http://msdn.microsoft.com • http://www.hypothetic.org/docs/msn/ietf_draft.php NTUEECS COBRA LAB

  36. Thanks for attention!

More Related