logo

const class

inet::TcpSocket

sys::Obj
  inet::TcpSocket

TcpSocket manages a TCP/IP endpoint.

Note: TcpSocket is marked as a const class to give protocol developers the flexibility to process sockets on multiple threads. However TcpSocket is inherently thread unsafe - therefore it is the developers responsibility to use this API in a thread safe manner.

Slots

bind

native This bind(IpAddress addr, Int port)

Bind this socket to the specified local address. If addr is null then the default IpAddress for the local host is selected. If port is null an ephemeral port is selected. Throw IOErr if the port is already bound or the bind fails. Return this.

Source

close

native Bool close()

Close this socket and its associated IO streams. This method is guaranteed to never throw an IOErr. Return true if the socket was closed successfully or false if the socket was closed abnormally.

Source

connect

native This connect(IpAddress addr, Int port, Duration timeout := null)

Connect this socket to the specified address and port. This method will block until the connection is made. Throw IOErr if there is a connection error. If a non-null timeout is specified, then block no longer then the specified timeout before raising an IOErr.

Source

in

native InStream in()

Get the input stream used to read data from the socket. The input stream is automatically buffered according to SocketOptions.inBufferSize. If not connected then throw IOErr.

Source

isBound

native Bool isBound()

Is this socket bound to a local address and port.

Source

isClosed

native Bool isClosed()

Is this socket closed.

Source

isConnected

native Bool isConnected()

Is this socket connected to the remote host.

Source

localAddress

native IpAddress localAddress()

Get the bound local address or null if unbound.

Source

localPort

native Int localPort()

Get the bound local port or null if unbound.

Source

make

new make()

Make a new unbound, unconnected TCP socket.

Source

options

native SocketOptions options()

Access the SocketOptions used to tune this socket. The following options apply to TcpSockets:

  • inBufferSize
  • outBufferSize
  • keepAlive
  • receiveBufferSize
  • sendBufferSize
  • reuseAddress
  • linger
  • receiveTimeout
  • noDelay
  • trafficClass Accessing other option fields will throw UnsupportedErr.

Source

out

native OutStream out()

Get the output stream used to write data to the socket. The output stream is automatically buffered according to SocketOptions.outBufferSize If not connected then throw IOErr.

Source

remoteAddress

native IpAddress remoteAddress()

Get the remote address or null if not connected.

Source

remotePort

native Int remotePort()

Get the remote port or null if not connected.

Source