Socket Programming Cal Poly Pomona Young CS380
IP Address Port Number What is a socket ? Wh A socket is one endpoint of a two-way communication link between two programs running on the network, which consists of IP Address AND Port Number CS380 Socket Programming
What do sockets do? Sockets TCP connection Server Client allows programs on different machines send data to one another CS380 Socket Programming
How to establish connections? Server Side: Create Server Socket Bind the Server Socket to a specific port Listen for incoming connection requests Accept requests and bind new sockets to different port numbers, then go back to listen Remarks: 0-1200 are reserved (well-known) port which are used only by OS CS380 Socket Programming
How to establish connections? Client Side: Create Socket Connect using IP Address and Port Number of the server process The port number used by client locally is allocated by OS dynamically CS380 Socket Programming
How to establish connections? ..... Server Process Client Server machine A Client machine B Ports Connection Request to (A,n) n Server creates Server Socket and listen to port number n Client creates Socket Client connects socket to machine A at port n Server rebind new connections to different ports and continue to listen CS380 Socket Programming
How to establish connections? ..... Server Process Client Server machine A Client machine B Ports n TCP connection established!! CS380 Socket Programming
Socket in Java Server Side ServerSocket, Socket ServerSocket ss = new ServerSocket(port); Socket s = ss.accept(); CS380 Socket Programming
Socket in Java Client Side: Socket Socket s = new Socket(hostname,port); CS380 Socket Programming