Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.

Similar presentations


Presentation on theme: "1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda."— Presentation transcript:

1 1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda

2 2 Network (Socket) Programming  Process sends/receives messages to/from its socket  Socket analogous to door  sending process shoves message out door  sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process process TCP with buffers, variables socket host or server process TCP with buffers, variables socket host or server Internet controlled by OS controlled by app developer  Socket is the interface (API) between application and transport layer

3 3 Addressing Processes  For a process to receive messages, it must have an identifier  A host has a unique32-bit IP address  Q: does the IP address of the host on which the process runs suffice for identifying the process?  A: No, many processes can be running on same host   We use ports  Process is identified by:  IP address,  Transport protocol, and  Port number  Example port numbers:  HTTP server: 80 (TCP)  Mail server: 25 (TCP)

4 4 Socket Programming  Socket API  introduced in BSD 4.1 UNIX, 1981  explicitly created, used, released by apps  client/server paradigm  provides two services reliable, byte stream-oriented unreliable datagram

5 5 Socket Programming using TCP  TCP service: reliable transfer of bytes from one process to another  virtual pipe between sender and receiver process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet

6 6 Socket Programming using TCP wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port= x, for incoming request: welcomeSocket = ServerSocket() create socket, connect to hostid, port= x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid ) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup

7 7 Socket Programming using TCP  Server process must first be running, and  creates a socket (door) that welcomes client’s contact, then wait  Client contacts server by creating local TCP socket using IP address, port number of server process  When client creates socket  client TCP establishes connection to server TCP  When contacted by client  server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients source port numbers and IPs used to distinguish clients

8 8 Socket programming using UDP  UDP Service: unreliable transfer of groups of bytes (datagrams) between client and server  no connection between client and server  no handshaking  sender explicitly attaches IP address and port of destination to each packet  server must extract IP address, port of sender from received packet  transmitted data may be received out of order, or lost

9 9 Socket Programming using UDP close clientSocket Server (running on hostid ) create socket, clientSocket = DatagramSocket() Client read reply from clientSocket Create datagram ( hostid,port=x,data) send datagram request using clientSocket create socket, port= x, for incoming request: serverSocket = DatagramSocket() read request from serverSocket write reply to serverSocket specifying client host address, port number


Download ppt "1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda."

Similar presentations


Ads by Google