0

I am working on an application using sockets. Essentially I want to stream data between two clients. Since I can't connect the two clients together directly (they aren't on the same network), I will need to connect the two through a server.

enter image description here

My client-side is written in Java but the server-side could be written in any language. I have already explored using socket.io etc. but the issue I ran in to is that Java doesn't have a nice websocket solution. What other options are there out there to achieve the same effect?

The solution I have in mind right now is basically "forwarding" the stream from one client to the other through the server, but there could be a better way out there...

1 Answer 1

1

There are a few ways you could solve this problem.I understand from your diagram and question your one of your client say client 1 is the server and your server is actually a proxy to redirect connections.The following solutions are in order of their complexity.

First is a networking solution: If connectivity between client 1 and client 2 is all you need to achieve. All you need to do in your clients is to add a route to the other client,add a route to client 1 to reach client 2 and vice versa.you do not have to change design of your program.

Second is a web proxy server:If you are running a web server in your server then you can configure web server to act as a reverse proxy.(Apache proxy instructions).This is useful if you do not have a lot of control over networking but have administrative privilege to your servers

Third is a programming solution:I guess you have the right solution in mind to write a program to "forward" the packets to the client.This is called proxy server so what proxy will do is receive requests from the client forward it to the server and receives the response from the server and forwards it to the client.But this does not guarantee performance you might have some performance issue.I would choose this way only when I have privileges that will allow me to change only the application I wrote and have restricted access to networking or servers and I will absolutely avoid going this road If at all possible for production systems.

Your statement about Java not having nice web socket is not true, Java's socket API is probably one of the most useful sockets out there.

4
  • Thanks for the variety of solutions! In solution 1, how would I connect the two clients directly? Commented Jul 14, 2014 at 13:12
  • If your are running a Linux box you can create a static route entry using ip route tool. (ip route add <dest_network/subnet_mask> via <gateway_ip_address>). Commented Jul 14, 2014 at 13:13
  • I ended up going with the third solution, and it's working well! Commented Jul 28, 2014 at 3:13
  • I am glad it helped,Keep a tab on your performance. Commented Jul 29, 2014 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.