In this Tutorials section we cover and explain Socket programming Server Side in details for freshers and experienced
previous | Home | Next |
Socket Programming for Server Side are showing as below program
If you connect server for the client then write a code.
import java.io.*; import java.net.*; class server { public static void main(String arr[]) { try { ServerSocket.Server=new ServerSocket(2500); System.out.println("Server is ready , waiting to connection request"); Socket s= Server.accept(); System.out.println("Request received, connection graunted"); BufferedReader b= new BufferedReader(new Input StreamReader(s.getInput Stream())); System.out.println("waiting for client's message"); String message=b.readLine(); thread.sleep(1000); System.out.println("Following message received:"+ message); System.out.println("Sending Acknowledgement"); printStream out= new printStream(s.get OutputSream()); thread.sleep(2000); out.println("Hello client , your message is received"); out.flush(); System.out.println("Acknowledgemwnt sent, closing connection"); thread.sleep(5000); s.close(); Server.Close(); System.out.Println("Connection Close"); } catch (Exception e) { System.out.println(e); } }
previous | Home | Next |