ISocket INTERFACE

An interface defining some common API for both client and server sockets. Although a couple of methods are shared, it's rarely programmed against such interface in practice due to the fundamental behavioral difference between the two types of socket.

All Members


TypeNameSignature
methodbindpublic void bind(string, int)
methodclosepublic void close()
methodgetLocalHostpublic String getLocalHost()
methodgetLocalPortpublic int getLocalPort()
methodgetSettingpublic var getSetting(System.Network.TCPOption)
methodgetStatepublic SocketState getState()

Methods


public void bind(string localHost, int localPort)

Bind this socket to a local address.

Parameters

  • localHost The local host, which can be an IP address or a domain name.
  • localPort The local port, a value between 0, 65535. If 0, it means no particular binding with local port and the socket may pick an arbitrary (a.k.a. ephemeral) one for connection.

public void close()

Close this socket. Once the socket is closed, all the streams from this socket will be closed too.


public String getLocalHost()

Get the local host. If the socket has not been bound, this returns null.

Returns

  • The local host this socket binds to. Null if the socket has not been bound to any.

public int getLocalPort()

Get the local port. If the port has not been bound, this returns 0.

Returns

  • The local port (1-65535) this socket binds to. 0 if the socket has not been bound to any.

public var getSetting(TCPOption opt)

Get the setting for a particular option. Not all options are valid for a concrete Socket type. The value this returns for invalid options is undefined.

Parameters

Returns

  • The value set for this option.

public SocketState getState()

Query the state of this socket.

Returns

  • The state of this socket.