Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package cd2020create;
  2. import java.io.*;
  3. import java.net.*;
  4. import java.util.*;
  5. import java.util.concurrent.*;
  6. public class Main {
  7. private ExecutorService executorService = Executors.newFixedThreadPool(999999);
  8.  
  9. public static void main(String[] args) throws IOException, NumberFormatException, InterruptedException {
  10. Scanner sc = new Scanner(System.in);
  11. ExecutorService threadPool = Executors.newCachedThreadPool();
  12. InetAddress ip = InetAddress.getLocalHost();
  13. String portnos = "0";
  14. System.out.println("Please enter a port to connect to (max 5 digits).");
  15. do {
  16. portnos = sc.next();
  17. try {
  18. Integer.parseInt(portnos);
  19. } catch (Exception e) {
  20. portnos = "100000000";
  21. }
  22. if (Integer.parseInt(portnos) > 99999) {
  23. System.err.println("Invalid port");
  24. portnos = "100000000";
  25. }
  26. } while (Integer.parseInt(portnos) > 99999);
  27. ServerSocket socket = new ServerSocket(Integer.parseInt(portnos), 50, ip);
  28. System.out.println("Connected to " + socket.getLocalSocketAddress());
  29. Socket sklocal = socket.accept();
  30. InputStream in = sklocal.getInputStream();
  31. OutputStream out = sklocal.getOutputStream();
  32. DataInputStream dataIn = new DataInputStream(in);
  33. DataOutputStream dataOut = new DataOutputStream(out);
  34. Socket sklocal2 = socket.accept();
  35. InputStream in2 = sklocal2.getInputStream();
  36. OutputStream out2 = sklocal2.getOutputStream();
  37. DataInputStream dataIn2 = new DataInputStream(in2);
  38. DataOutputStream dataOut2 = new DataOutputStream(out2);
  39. while (true) {
  40. dataOut2.writeUTF(dataIn.readUTF());
  41. dataOut.writeUTF(dataIn2.readUTF());
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement