fork download
  1. import java.net.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Server{
  6.  
  7. //port number should be more than 1024
  8.  
  9. public static final int PORT = 1025;
  10.  
  11. public static void main( String args[])
  12. {
  13. ServerSocket sersock = null;
  14. Socket sock = null;
  15. System.out.println(" Wait !! ");
  16.  
  17. try
  18. {
  19. // Initialising the ServerSocket
  20. sersock = new ServerSocket(PORT);
  21.  
  22. // Gives the Server Details Machine name,
  23. Port number
  24.  
  25. System.out.println("Server Started :"+sersock);
  26.  
  27. try
  28. {
  29.  
  30. // makes a socket connection to particular
  31. client after
  32. // which two way communication take place
  33.  
  34. sock = sersock.accept();
  35.  
  36. System.out.println("Client Connected :"+ sock);
  37.  
  38. // Receive message from client i.e Request
  39. from client
  40.  
  41. DataInputStream ins = new
  42. DataInputStream(sock.getInputStream());
  43. // Send message to the client i.e Response
  44.  
  45. PrintStream ios = new
  46. sPrintStream(sock.getOutputStream());
  47. ios.println("Hello from server");
  48. ios.close();
  49.  
  50. // Close the Socket connection
  51.  
  52. sock.close();
  53.  
  54. }
  55. catch(SocketException se)
  56. {
  57. System.out.println("Server Socket
  58. problem "+se.getMessage());
  59. }
  60. catch(Exception e)
  61. {
  62. System.out.println("Couldn't start "
  63. + e.getMessage()) ;
  64. }
  65.  
  66. // Usage of some methods in Socket class
  67.  
  68. System.out.println(" Connection from : " +
  69. sock.getInetAddress());
  70.  
  71. } // main
  72.  
  73. } // Server class
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.nim(1, 11) Error: cannot open 'java'
stdout
Standard output is empty