Class Socket extends Transport

Introduction

This class wraps the Synergy/DE Socket API as an implementation of the abstract Transport, as used by Telnet.

Contents

  1. Introduction
  2. Contents
  3. Explanation of symbols used
  4. Member reference
    1. (constructors)
    2. Accept - Accept a connection
    3. Close - Close a socket
    4. Connect - Connect to a host
    5. Connected - Is socket connected?
    6. GetHostByName - Retrieve an IP address for a host name
    7. IPAddress - Convert a dotted IP address to an integer
    8. Listen - Establish a port on which to listen for connections
    9. Receive - Receive text from a sender
    10. Send - Send text to a receiver
    11. SocketException - exception thrown on socket errors

Explanation of symbols used

Words in italics indicate an instance of a class. The word corresponds to the class name, except where more than one instance is represented in the same statement. In that case a number (2, 3, etc.) is appended to the class name.

Words in normal typeface are to be taken literally (required punctuation, class name in a static reference, method name, etc.)

The symbol => is used to separate an expression (on the left) from its return value (on the right).

An ellipsis (...) indicates that the previous argument may be repeated any number of times. The description will indicate whether one instance is required.

Member reference

constructors

socket = new Socket()
socket = new Socket(i)
Creates a new socket. If i is passed, it must be one of the two values SS_SOCK_STREAM or SS_SOCK_DGRAM defined in DBLDIR:synsock.def. If not specified, SS_SOCK_STREAM is assumed.

method Accept

socket.Accept() => socket2
This method waits for connection requests on socket and returns socket2 on which to carry the conversation. You must first establish socket as a socket for listening before calling this method by calling the Listen method. Typically, a server will call Listen once, and then Accept in a loop. If an error occurs, a SocketException will be thrown.

method Close

socket.Close() => boolean
Closes a socket, if it is open, returning true if successful. If an error occurs, no exception is thrown. This method is called automatically in the destructor if the socket is open, but you may wish to call it explicitly to control timing.

method Connect

socket.Connect(i, i2) => boolean
Connect to the host at IP address i on port i2. To translate a host name or a dotted form of the address to an integer as required for i, see the GetHostByName or IPAddress methods, respectively. If an error occurs, a SocketException will be thrown.

property Connected

socket.Connected => boolean
This read-only property returns true if the socket is connected, otherwise false.

static method GetHostByName

Socket.GetHostByName(a) => i
This static method returns an IP address for the host named in a. If an error occurs, a SocketException will be thrown.

static method IPAddress

Socket.IPAddress(a) => i
This static method returns an IP address for the dotted form of the address in a. If an error occurs, a SocketException will be thrown.

method Listen

socket.Listen(i) => boolean
This method establishes a port i on which to listen for connections as a server. If successful, it returns true. If an error occurs, a SocketException will be thrown.

override method Receive

socket.Receive(a) => i
This method receives data from an open socket and returns it in the parameter a, which must be writable. The method returns the number of characters returned in a.

override method Send

socket.Send(a) => boolean
This method sends the characters in a to the open socket. It returns true if successful. If an error occurs, a SocketException will be thrown.

class SocketException extends Synergex.SynergyDE.SynException

This class of exception is thrown whenever an unexpected socket error occurs. Its public member SocketStatus is an integer that contains the socket status returned. Its inherited Message member is set to "Socket error: n", where n is the socket status code.