How to Print Socket ID in Java

When you form a connection to another computer or network device in a Java program you are writing, your program automatically connects to a particular "socket" or doorway on the other computer or network device. The socket you connect to will have a particular ID, and you can print this socket ID out in your program if you need to debug the connection.

Instructions

    • 1

      Open your Java file in your chosen programming environment.

    • 2

      Initialize the socket connection by typing "ServerSocket newConnection = new ServerSocket(#);" on a new line.

    • 3

      Retrieve the ID of the socket by typing "Socket newSocket = newConnection.accept();" on a new line.

    • 4

      Print the socket ID by typing "out.print(newSocket);" on a new line.

Related Searches:

Comments

Related Ads

Featured