Skip to main content

Posts

Showing posts with the label program using socket program to send the string "hello" to the client

What is the task of Socket class? Write program using socket program to send the string "hello" to the client.

 The Socket class in Java provides a way to create client-side sockets that can connect to a server on a given IP address and port number. Once the connection is established, the client and server can exchange data through the socket. Here's an example Java program that creates a server socket and sends the string "hello" to the client: import java.net.*; import java.io.*; public class Server {     public static void main(String[] args) {         try {             // create a server socket object             ServerSocket serverSocket = new ServerSocket(8080);                          // wait for a client to connect             Socket clientSocket = serverSocket.accept();                          // create an output stream to send data t...