Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cd2020create;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import java.util.concurrent.*;
- public class Main {
- private ExecutorService executorService = Executors.newFixedThreadPool(999999);
- public static void main(String[] args) throws IOException, NumberFormatException, InterruptedException {
- Scanner sc = new Scanner(System.in);
- ExecutorService threadPool = Executors.newCachedThreadPool();
- InetAddress ip = InetAddress.getLocalHost();
- String portnos = "0";
- System.out.println("Please enter a port to connect to (max 5 digits).");
- do {
- portnos = sc.next();
- try {
- Integer.parseInt(portnos);
- } catch (Exception e) {
- portnos = "100000000";
- }
- if (Integer.parseInt(portnos) > 99999) {
- System.err.println("Invalid port");
- portnos = "100000000";
- }
- } while (Integer.parseInt(portnos) > 99999);
- ServerSocket socket = new ServerSocket(Integer.parseInt(portnos), 50, ip);
- System.out.println("Connected to " + socket.getLocalSocketAddress());
- Socket sklocal = socket.accept();
- InputStream in = sklocal.getInputStream();
- OutputStream out = sklocal.getOutputStream();
- DataInputStream dataIn = new DataInputStream(in);
- DataOutputStream dataOut = new DataOutputStream(out);
- Socket sklocal2 = socket.accept();
- InputStream in2 = sklocal2.getInputStream();
- OutputStream out2 = sklocal2.getOutputStream();
- DataInputStream dataIn2 = new DataInputStream(in2);
- DataOutputStream dataOut2 = new DataOutputStream(out2);
- while (true) {
- dataOut2.writeUTF(dataIn.readUTF());
- dataOut.writeUTF(dataIn2.readUTF());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement