Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. package com.tcpserver;
  2.  
  3. import java.io.IOException;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6. import java.util.Scanner;
  7.  
  8. public class TCPServer {
  9. public static void main(String[] args) throws IOException {
  10. Scanner scanner = new Scanner(System.in);
  11. int port = scanner.nextInt();
  12. scanner.close();
  13.  
  14. ServerSocket serverSocket = new ServerSocket(port);
  15. Socket clientSocket = serverSocket.accept();
  16.  
  17. System.out.println("Client connected");
  18.  
  19. clientSocket.close();
  20. serverSocket.close();
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement