Search code examples
javaserverclientraw-sockets

Connect 2 server sockets in JAVA


I need to write a Java code that allows Client1Socket to connect to Server1Socket, Server1Socket to connect to Server2Socket and Server2Socket to connect to Client2Socket. Can anybody give me a simple example so I can apply in to my code? Thank you very much!


Solution

  • Server A will have to open a Socket to connect to server B, and it will have to copy data between that socket and the socket it accepted from client A.

    Client B will have to connect to server B, not the other way around.

    Server B will have to copy data between the socket it accepts from server A and the socket it accepts from client B.