Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class server {
- static DataInputStream in;
- static DataOutputStream out;
- public static void main(String[] args) throws IOException{
- ServerSocket serverSocket = null;
- String ip = "localhost";
- try{
- serverSocket = new ServerSocket(6666, 8, InetAddress.getByName(ip));
- }catch(IOException e)
- {
- System.out.println("Could not listen on port: 6666");
- System.exit(-1);
- }
- Socket clientSocket = null;
- try{
- clientSocket = serverSocket.accept();
- }catch(IOException e)
- {
- System.out.println("Accept failed: 6666");
- System.exit(-1);
- }
- out = new DataOutputStream(clientSocket.getOutputStream());
- in = new DataInputStream(clientSocket.getInputStream());
- while(clientSocket.getKeepAlive())
- {
- out.flush();
- in.read();
- }
- clientSocket.close();
- serverSocket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement