- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Sockets?
Sockets are used to provide the capability of making connections from one application running on one machine to another running on a different machine. A socket abstraction consists of the data structure that holds the information needed for communication, and the system calls that manipulate the socket structure. Once a socket is created, it can be used to wait for an incoming connection (passive socket) or can be used to initiate a connection (active socket).
A client can establish an active connection to a remote server by creating an instance of a socket. To establish a server connection and bind it to a particular port number, we should create an instance of a server socket. A server socket listens on a TCP port for a connection from a client (passive socket). When a client connects to that port, the server accepts the connection.
Once the connection is established, the client and server can read from and write to the socket using input and output streams. Streams are ordered sequences of data that have a source (input stream), or destination (output stream). Once the client or server finishes using the socket, the socket structure is de-allocated.
Client/Server Java Statement
The Socket class provides a client-side socket interface. A client can establish an active connection to a remote server by creating an instance of Socket as follows: Socket <connection>= new Socket (<host name>, <port number>);
The variable gives the name of the server to connect to; and <port number> should match the port number at the server end.
The ServerSocket class provides a server-side socket interface. To establish a server connection and bind it to a particular port number, we should create an instance of ServerSocket as follows −
ServerSocket <connection> = new ServerSocket(<port number>);
Once the connection is established, the client and server can read from and write to the socket using input and output streams. Streams in Java are used for Input/ Output. They are ordered sequences of data that have a source (input stream), or destination (output stream).
- Interprocess Communication with Sockets
- Advantages and Disadvantages of Java Sockets
- Sending and Receiving Data with Sockets in android
- Why are electric witches, plugs and sockets made of thermosetting plastics?
- What is motion? What is rest?
- 1). What is additive identity?2). What is Reciprocal?3). What is multiplicative inverse?
- What is “Rangoli’ and what is its significance?
- What is an orbit? What is its shape?
- What is radical and what is an ion?
- What is plasma and what is its function?
- What is power? What is its SI unit ?
- What is hydrogenation? What is its industrial application?
- 1.What is Glycolysis? n2. What is Trypsin?
- What is Java API and what is its use?