A socket is basically an endpoint or a plugin that allows communication between devices over a network. It is uniquely identified by an IP address and a port number.
I implemented a server/client chat system in Java using sockets : Multi-Threaded Groupchat
- Binds a socket to a chosen IP address and port.
- Listens for incoming client connections.
- Accepts a connection and creates a dedicated socket for that client.
- Receives messages from the client and echoes them back until the client disconnects.
- Connects to the server using its IP address and port.
- Sends a message to the server.
- Receives the server’s reply.
- Prints the reply, then closes the connection.
- Run the
ServerClassin your IDE (exp, IntelliJ IDEA).
- Open multiple terminals (PowerShell or similar).
- Run the client class with:
java -cp bin client.SocketClient