0

Not really sure how to title this question so here it goes.

I am trying to determine if it is possible to setup a client/server and have the server just handle requests (easy). But the hard part is I want to see if it is possible to have two clients talk to the server and the server then gives the clients each others sockets allowing them to talk directly to each other.

Client1----|
 |         ---Server
Client2----|

So both clients would initially start talking to the server, then the server would return to each client the other persons socket. Which at the moment is not possible because they are not serialized. Is there a way to pass something back to the clients to allow them to bypass opening ports for client to client communication?

Justin
  • 866
  • 1
  • 13
  • 29
  • what are your findings so far about the described problem? – DevDio Jun 17 '18 at 17:52
  • The main issue is that you cannot serialize sockets. And since ServerSocket is the one that actually creates the socket I dont know of a good way to overwrite the socket with my own implementation. Not sure how to acomplish this.... – Justin Jun 17 '18 at 18:31
  • 4
    Why would you ever want to serialize Sockets? Makes no sense. Instead you need to hook up two clients. Please look at [this similar question](https://stackoverflow.com/questions/2578254/connect-two-client-sockets) – Hovercraft Full Of Eels Jun 17 '18 at 18:37
  • Also look at [these similar questions](https://www.google.com/search?q=java+connect+client+sockets+together+site:stackoverflow.com) – Hovercraft Full Of Eels Jun 17 '18 at 18:37
  • 2
    TCP is point-to-point. So no, the clients need to establish a new connection with each other, with all the difficulties of getting through NAT etc. But the server can help by telling the client it's "external" IP. So only the port needs to be opened, e.g. via upnp. – rustyx Jun 17 '18 at 18:37
  • Ok so then let me ask the question slightly different, by using java library for upnp is it possible to have the server tell the clients where to connect and then the clients connect to each other without opening port on the router? (I believe that is possible with the upnp?). Sorry just trying to understand options for talking straight client to client. – Justin Jun 18 '18 at 18:52
  • Ahh, those links are kind of what i am talking about. A middle man server. Reading now :P – Justin Jun 18 '18 at 18:54

0 Answers0