Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. public class server {
  4.    
  5.     static DataInputStream in;
  6.     static DataOutputStream out;
  7.    
  8.     public static void main(String[] args) throws IOException{
  9.  ServerSocket serverSocket = null;
  10.  String ip = "localhost";
  11.  try{
  12.      serverSocket = new ServerSocket(6666, 8, InetAddress.getByName(ip));
  13.  }catch(IOException e)
  14.  {
  15.      System.out.println("Could not listen on port: 6666");
  16.      System.exit(-1);
  17.  }
  18.  
  19.  Socket clientSocket = null;
  20.  try{
  21.      clientSocket = serverSocket.accept();
  22.  }catch(IOException e)
  23.  {
  24.      System.out.println("Accept failed: 6666");
  25.      System.exit(-1);
  26.  }
  27.  out = new DataOutputStream(clientSocket.getOutputStream());
  28.  in = new DataInputStream(clientSocket.getInputStream());
  29.  while(clientSocket.getKeepAlive())
  30.  {
  31.      out.flush();
  32.      in.read();
  33.  }
  34.  clientSocket.close();
  35.  serverSocket.close();
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement