# IO:Socket

### Import List

        IO
        IO:Address

Class List
Server |
Socket |

Class Summary: Server [Detail]

      +--IO:Socket.Server

Field Summary
fd-: FileDescriptor
Constructor Summary
NewServer(): Server Create an unconnected socket.
Method Summary
Accept(): Socket Accepts a connection request from a remote socket.
Bind(Socket, LONGINT) Bind this socket to a local address and switch it to listening mode.
Close() Close this socket.
SetBlocking(BOOLEAN)
SetReuseAddress(BOOLEAN)

Class Summary: Socket [Detail]

      +--IO:Socket.Socket

Field Summary
fd-: FileDescriptor
Constructor Summary
New(): Socket Create an unconnected socket.
Method Summary
Bind(Socket) Bind this socket to a local address.
Close() Close this socket.
Connect(Socket): BOOLEAN Connect this socket to the remote end point.
FinishConnect(): BOOLEAN Try to complete socket connect after Socket.Connect has been called on a non-blocking socket.
RemoteAddress(): Socket Returns the address of the remove end of a connection.
SetBlocking(BOOLEAN)

Procedure Summary
Read(Socket, VAR ARRAY OF BYTE, LONGINT, LONGINT): LONGINT Exported for the sake of IO:SocketChannel.
Write(Socket, ARRAY OF BYTE, LONGINT, LONGINT): LONGINT Exported for the sake of IO:SocketChannel.

Class Detail: Server

Field Detail

### fd

    FIELD fd-: FileDescriptor

Constructor Detail

### NewServer

    PROCEDURE NewServer(): Server
      RAISES Error;

> Create an unconnected socket.

Method Detail

### Accept

    PROCEDURE (s: Server) Accept(): Socket
      RAISES Error;

> Accepts a connection request from a remote socket.

> On success, result is the local socket of the connection. If the server socket is in non-blocking more, and there are no more pending connections, then result is NIL. An error raises an exception of type IO.Error.

### Bind

    PROCEDURE (s: Server) Bind(bindPoint: Socket;
                   queueSize: LONGINT)
      RAISES Error;

> Bind this socket to a local address and switch it to listening mode. queueSize specifies the length of the queue for pending connections.

> If the address is NIL, then the system will pick up an ephemeral port and a valid local address to bind the socket.

### Close

    PROCEDURE (s: Server) Close()
      RAISES Error;

> Close this socket.

> Once a socket has been closed, it is not available for further networking use. That is, it cannot be reconnected or rebound; a new socket needs to be created.

### SetBlocking

    PROCEDURE (s: Server) SetBlocking(block: BOOLEAN)
      RAISES Error;

### SetReuseAddress

    PROCEDURE (s: Server) SetReuseAddress(on: BOOLEAN)
      RAISES Error;

Class Detail: Socket

Field Detail

### fd

    FIELD fd-: FileDescriptor

Constructor Detail

### New

    PROCEDURE New(): Socket
      RAISES Error;

> Create an unconnected socket.

Method Detail

### Bind

    PROCEDURE (s: Socket) Bind(bindPoint: Socket)
      RAISES Error;

> Bind this socket to a local address.

> If the address is NIL, then the system will pick up an ephemeral port and a valid local address to bind the socket.

### Close

    PROCEDURE (s: Socket) Close()
      RAISES Error;

> Close this socket.

> Once a socket has been closed, it is not available for further networking use. That is, it can't be reconnected or rebound; a new socket needs to be created.

### Connect

    PROCEDURE (s: Socket) Connect(endPoint: Socket): BOOLEAN
      RAISES Error;

> Connect this socket to the remote end point. Result is TRUE if the connection has been established, and FALSE if the process is still in progress when this method returns.

### FinishConnect

    PROCEDURE (s: Socket) FinishConnect(): BOOLEAN
      RAISES Error;

> Try to complete socket connect after Socket.Connect has been called on a non-blocking socket. Result is TRUE on success, and FALSE if the connection process cannot be completed at this time.

### RemoteAddress

    PROCEDURE (s: Socket) RemoteAddress(): Socket
      RAISES Error;

> Returns the address of the remove end of a connection.

### SetBlocking

    PROCEDURE (s: Socket) SetBlocking(block: BOOLEAN)
      RAISES Error;

Procedure Detail

### Read

    PROCEDURE Read(s: Socket;
                   VAR buffer: ARRAY OF BYTE;
                   start: LONGINT;
                   length: LONGINT): LONGINT
      RAISES Error;

> Exported for the sake of IO:SocketChannel.

### Write

    PROCEDURE Write(s: Socket;
                    buffer: ARRAY OF BYTE;
                    start: LONGINT;
                    length: LONGINT): LONGINT
      RAISES Error;

> Exported for the sake of IO:SocketChannel.