python socket - How to instantiate a socket - java socket tutorial - socket - socket io - python socket - java socket - socks proxy - socket programming



How to instantiate a socket class object

Instantiating a socket can be done in various ways.

  • By 2 line declaration & instantiation:
    • First we need to define a variable which will hold a Socket class object:
Socket socket;
click below button to copy the code. By Socket tutorial team
  • Then we can create a Socket class object:
socket = new Socket();
click below button to copy the code. By Socket tutorial team
  • We can also make a one line definition & instantiation:
Socket  socket = new Socket();
click below button to copy the code. By Socket tutorial team
  • Both ways will create an unconnected socket.
  • We can use other parameterized constructors to instantiate connected or unconnected socket class object:

For details see class doc specs:

https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html


Related Searches to How to instantiate a socket