Contents:
Basics of Networking
What Is Socket???
Basics of Networking:
TCP/IP:
A protocol is a set of rules that determine how things communicate with each other. The software which manages Internet communication follows a suite of protocols called TCP/IP. The Internet Protocol (IP) determines the format of the information as it is transferred. The Transmission Control Protocol (TCP) dictates how messages are reassembled and handles lost information.
What Is a Socket???
SOCKETS:
Sockets are the basic mechanism for inter-process communication provided by the operating system. A socket is essentially a defined endpoint for communication between two processes. It provides a full duplex channel to two different parties involved in communication. There are two separate data streams, one going in and one going out.
In Package java.net
java.net.Socket Implements client sockets (also called just sockets). An endpoint for communication between two machines. Constructor and Methods Socket(String host, int port): Creates a stream socket and connects it to the specified port number on the named host. InputStream getInputStream() OutputStream getOutputStream() close()
In Package java.net
java.net.ServerSocket Implements server sockets. Waits for requests to come in over the network. Performs some operation based on the request. Constructor and Methods ServerSocket(int port) Socket Accept(): Listens for a connection to be made to this socket and accepts it. This method blocks until a connection is made.
Types of Socket:
User Datagram Protocol (UDP) Sockets:
Sockets using UDP provide a datagram service. They receive and send discrete packets of data. UDP is a connectionless protocol, meaning that there is no connection setup time as there is in TCP. UDP is unreliablepackets are not guaranteed to be sent or received in the right order. UDP is mainly used for applications such as multimedia streaming and online gaming.
Client
Client socket Initiate a TCP connection to the server by creating a socket object. (Three-way handshake) Specify the address of the server process, namely, the IP address of the server and the port number of the process.
Client
TCP
setup
create socket, connect to hostid, port=x clientSocket = Socket() send request using clientSocket
Thank You