Problem with opening Java ports

0

I am learning java and trying to do a client-server type chat using TCP, which will work online, the fact is that what I have done so far works very well locally, but when putting a remote ip address the client It connects very well to the server because it is what port has to be open, but when the server has to send something to the clients how do I use ports that are open for remote connections? Because for example in my router only I have open the port that my server uses to listen to, or how could I open the ports of the clients?

    
asked by latiagertrutis 18.06.2017 в 14:39
source

2 answers

0

The server is the program that has the ports open, listening. The customer initiates the communication .

When in a system the elements can act both as clients and servers, it is called Peer-to-Peer (P2P).

The main problem with these systems is not to report the IPs / ports (it is enough for the "clients" to send a message to the "server" informing of which ports they have open), but normally the client will not access directly from the internet, It will be in a local network, so you will have to configure NAT / Firewall so that communication is possible. If it's a domestic customer, you probably will not have a clue how to do it; if it is a company, possibly the IT department will not want to do so because each open port is a security risk.

The simplest thing is to have your clients connect regularly to your server to see if there is new information, and that in the answer the server will provide them with the information they need. That technique is called polling .

    
answered by 18.06.2017 в 15:00
0

Ok I think I could find the error in my code and it was that I had the socket closed, anyway I expose the case to verify if a connection in this way would be correct for a real use: Having the server listening when connect a client this creates a socket between client and server that will remain open until the client disconnects and where all the information that the client and the server should exchange will travel.

    
answered by 18.06.2017 в 16:11