Skip to main content

Posts

Showing posts with the label chat programs using TCP

What is socket programming? Create chat programs using TCP.

 Socket programming is a way of communication between two nodes (a client and a server) over a network using sockets. Sockets are endpoints of a two-way communication link between two programs running on a network. They allow data to be transferred between the client and server applications, enabling them to exchange messages, files, and other data. Here is an example of a simple chat program using TCP sockets: Server Code: import java.io.*; import java.net.*; public class ChatServer {     public static void main(String[] args) throws IOException {         ServerSocket serverSocket = new ServerSocket(8000);         System.out.println("Server is running...");         Socket socket = serverSocket.accept();         System.out.println("Connected to client...");         BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));       ...