Wei Chen
Wei Chen

Reputation: 23

tcp relay server using the same port

Here is the situation. I want to replay the traffic coming from one client to another client. These clients are connected to the server using the same port. To be more specific, I want to stream data from a client to another while the server is acting like a network switch. The sending client is sending music stream so that it is essential that the server relays the stream without writing into files. I wonder if I can implement this using TCP without writing into files? and I am using Java for it.

Upvotes: 0

Views: 696

Answers (2)

Yasir Majeed
Yasir Majeed

Reputation: 741

Yes you can do that. Both clients will connect with the server, the server when receives the data from recv() will call send() for the other client. You can use the same buffer that will be used with recv() and send().

Upvotes: 1

user207421
user207421

Reputation: 311039

Yes you can, just listen at the port, accept both connections, and copy between them in both directions simultaneously.

Upvotes: 1

Related Questions