This document provides an overview of socket programming in Java. It discusses how client-server applications use sockets to communicate over a network. Sockets are identified by an IP address and port number. The document explains TCP and UDP socket programming in Java. For TCP, it describes how the server creates a welcoming socket to accept client connections. For both TCP and UDP, it outlines the basic interactions between client and server sockets. The document concludes by noting that socket programming is easy in Java and real-time applications typically use threads to handle each socket.
Introduction to the topic of Socket Programming in Java, presented by Narendran Thangarajan, a student from SSN College of Engg.
Explains how the Internet has transformed communication and the increased demand for software developers for internet-enabled applications.
Describes the layout of client-server applications, highlighting the role of clients and servers in providing web services.
Defines sockets as communication endpoints, first introduced in UNIX, and presents the concept of socket addresses comprising IP address and port number.
Illustrates the structure of an IP address and emphasizes the importance of port numbers in network communication, showing examples of destination sockets.
Further details on how port numbers identify processes, with examples of different ports associated with various applications; explains the transport and network layers.
Illustrates how sockets facilitate communication between processes across different systems and provides examples of socket pairs.
Outlines various network layers (Application, Transport, Network, Link) and their respective roles, along with the programming interface related to sockets.
Introduces the practical approach to socket programming, transitioning into the specifics of TCP socket programming.
Details the steps in TCP socket programming, including server initiation, welcoming sockets, and client connections to establish communication.
Visual representation and steps involved in the connection establishment process between server and client.
Explains different socket types: ServerSocket for servers and Socket for clients, and their role in establishing connections.
Explains the concept of streams associated with client and server sockets, showcasing input and output streams.
Differentiates between TCP and UDP through their connection establishment mechanisms and illustrates UDP's connectionless communication.
Initiates the coding segment of the presentation, focusing on practical implementation of socket programming.
Summarizes socket programming in Java as user-friendly and highlights real-time processing via threads.
Opens the floor for audience questions regarding the presentation on socket programming.
SOCKET PROGRAMMING INJAVA Narendran Thangarajan, @naren_live, II Year, BE, CSE, SSN College of Engg, Chennai.
2.
What started itall.. Internet has emerged as a global ubiquitous media for communication It has changed the way we live, learn, enjoy, communicate, interact, engage, etc. To take advantage of this, businesses are ceaselessly trying to offer their services through the internet. So a huge demand for software developers good in creating internet-enabled applications.
3.
Client Server Applications The Web Service is provided by the server and the clients use these services Client Server Network Client machine Server machine A client, where sockets and network This is A server, come in !!
4.
Sockets Introduced inBSD 4.1 UNIX 1981. Sockets are the endpoints of any communication over the internet. Sockets are identified by socket addresses. Socket Address = IP Address + Port Number
5.
Why IP Address+ Port number? • IP Address is of the form 10.0.0.1 • Port Number can be anything from 0 to 65,535.
Destination Socket =10.0.0.2 : 80 IP Address -> MAC Address – Locate the specific system 10.0.0.1 10.0.0.2
8.
Port Number –Process specific Port 10000 Port 11000 Port 120000
9.
Understanding Ports OutLook AVG Gmail YM Express Update Port 1 Port 2 Port 3 Port 4 Transport Layer Packet Port num data Network layer
10.
Thus virtually,sockets are a connection between the two processes in different systems. Eg : Let the socket pairs be 10.0.0.1 : 80 and 20.0.0.1 : 2000 192.168.21.10 : 3000 and 192.168.100.1 : 6000
11.
Networking Basics –the larger picture Applications Layer Standard apps HTTP TCP STACK FTP Telnet Application User apps (http,ftp,telnet,…) Transport Layer Transport TCP (TCP, UDP,..) UDP Network Network Layer (IP,..) IP Link Layer Link (device driver,..) Device drivers
12.
Network Basics -Where are these sockets? Applications Layer Standard apps HTTP TCP STACK FTP Telnet Application User apps (http,ftp,telnet,…) Programming Interface: Sockets SOCKETS Transport Transport Layer (TCP, UDP,..) TCP UDP Network (IP,..) Network Layer Link IP Link Layer (device driver,..) Device drivers
Socket Programming withTCP Server starts first.. Server Process must be running first Server must have created a socket which welcomes client’s connection. (Welcoming socket) Client contacts server by.. Creating Client local TCP socket Specify IP Address and port number of server process. When Client socket is created, the connection is established. When connection is established, server creates a new socket (Connection Socket) to communicate with that client and the Welcoming socket is once again waiting for connections for other clients.
15.
Client/Server Socket Interactionin TCP Server create socket, port=x, for incoming request: welcomeSocket = ServerSocket() Client wait for incoming TCP create socket, connection request connection setup connect to hostid, port=x connectionSocket = clientSocket = welcomeSocket.accept() Socket() send request using read request from clientSocket connectionSocket write reply to connectionSocket read reply from connectionSocket close connectionSocket close clientSocket
16.
Step 1 : Connection request port Server Client Step 2 : port Server port Client port Connection
17.
Types of Socketsin TCP ServerSocket – the socket used by servers Socket – Socket used by clients Create a ServerSocket in the server and make it to wait for connections from Sockets from other clients
18.
The concept ofStreams Client output Server input stream stream Client Server socket socket Client input Server output stream stream
19.
Socket Programming withUDP No Connection between client and server. No handshaking The sender has to explicitly mention the IP address and the port of the destination. The server should extract the IP Address of the datagram everytime. Uses DatagramSocket.
20.
Client/server socket interaction: UDP Server Client create socket, create socket, port=x, for clientSocket = incoming request: DatagramSocket() serverSocket = DatagramSocket() Create, address (hostid, port=x), send datagram request using clientSocket read request from serverSocket write reply to serverSocket read reply from specifying client clientSocket host address, port number close clientSocket
Conclusion Socket Programmingis very easy in Java. Usually each and every socket is handled by a separate thread in real-time client/server environments.