Search code examples
javatcpport

Java computer to computer connection?


Is it possible to have two computers socket-connect to each other without any server involved in Java? If so, how? I've only seen examples of server-client connections where the server is permanent.

For example:

  1. 2 people, person A and person B, want to connect using this application.
  2. Person A runs application, clicks "host".
  3. Application hands person A a code (IP+port?) and begins listening.
  4. Person B clicks "join" and types in code.
  5. Person B's computer sees Person A's computer and they connect. Person A accepts connection.

I've never really understood this well.


Solution

  • In your scenario, person A's PC would be acting as the server and person B's would be acting as the client. Even if it is only temporary, the fact that A is listening for a connection means that it is acting as a server.