SYNAPSE - Synchronous TCP/IP Library for Delphi
Other related information can be found at http://www.ararat.cz/synapse/
Class: TTCPBlockSocket
- Properties:
- socket:TSocket
Socket identifier. Suitable for "manual" calls to WinSock API or manual connection of socket to a previously created socket.
- LocalSin:TSockAddrIn
Structure describing local socket side.
- RemoteSin:TSockAddrIn
Structure describing remote socket side.
- LastError:integer
Last WinSock operation error code. Error codes are described in Winsock documentation. By calling function GetErrorDesc(ErrorCode:integer):string you can get error code string description.
- Protocol:integer
Winsock protocol identifier.
- RaiseExcept:boolean
If true, winsock errors raises exception. Default value is false.
- Methods:
- Procedure CreateSocket
Creates new socket.
- Procedure CloseSocket
Destroy socket in use. Future data sent to this socket will be ignored. This method is also automatically called from obejct destructor.
- procedure Bind(ip,port:string)
Connects socket to local IP address and PORT. IP address may be numeric or symbolic (192.168.74.50, cosi.nekde.cz). The same for PORT - it may be number or mnemonic port (23, telnet).If port value is 0, system chooses itself and conects unused port in the range 1024 to 4096. Structure LocalSin is filled after calling this method.
- procedure Connect(ip,port:string)
Connects socket to remote IP address and PORT. The same rules as with BIND method are valid. The only exception is that PORT with 0 value will not be connected. After call to this method a communication channel between local and remote socket is created. Structures LocalSin and RemoteSin will be filled with valid values.
Local socket is assigned automatically if not controlled by previous call to BIND method.
- function SendBuffer(buffer:pointer;length:integer)
Sends data of LENGTH from BUFFER address via connected socket. System automatically splits data to packets.
- procedure SendByte(data:byte)
One data BYTE is sent via connected socket.
- procedure SendString(data:string)
Send data string via connected socket.
- function RecvBuffer(buffer:pointer;length:integer):integer
Waits until allocated buffer is filled by received data. Returns number of data received, which equals to LENGTH value under normal operation. If it is not equal the communication channel is possibly broken.
- function RecvByte(timeout:integer):byte
Waits until one data byte is received which is also returned as function result. If no data is received within TIMEOUT (in milliseconds)period, LastError is set to WSAETIMEDOUT.
- function Recvstring(timeout:integer):string
Method waits until data string is received. This string is terminated by LF character. The resulting string is returned without this termination (CR LF). If no data is received within TIMEOUT (in milliseconds)period, LastError is set to WSAETIMEDOUT. Methods serves for line protocols implementation and uses its own buffers to maximize operation power. Therefore do NOT use this method with other methods for data receiving because of posiible data loss.
- function PeekBuffer(buffer:pointer;length:integer):integer
Same as RecvBuffer, but readed data stays in input buffer.
- function PeekByte(timeout:integer):byte
Same as RecvByte, but readed data stays in input buffer.
- function WaitingData:integer
Returns number of received bytes waiting for picking. 0 is returned when there is no such data.
- function CanRead(Timeout:integer):boolean
Return TRUE, if you can from socket read any data. Status is tested for time Timeout (in milliseconds). If value in Timeout is 0, status is only tested and continue. If value in Timeout is -1, run is breaked and waiting for read data maybe forever.
- function CanWrite(Timeout:integer):boolean
Return TRUE, if you can to socket write any data (not full sending buffer). Status is tested for time Timeout (in milliseconds). If value in Timeout is 0, status is only tested and continue. If value in Timeout is -1, run is breaked and waiting for write data maybe forever.
- procedure SetLinger(enable:boolean;Linger:integer)
Sets linger. Enabled linger means that the system waits another LINGER (in milliseconds) time for delivery of sent data.
- procedure Listen
Sets socket to receive mode. It is necessary to use BIND function call before this method to select receiving port.
- function Accept:TSocket
Waits until new incoming connection comes. After it comes a new socket is automatically created (returned by this function) and connected to free ports determined by system.
- function SockCheck(SockResult:integer):integer
If you "manually"call WinSock API functions, forward their return code as parameter to this function, which evaluates it, eventually calls WSAGetLastError and found error code returns and stores to LastError.
- function LocalName:string
Returns local computer name as numerical or symbolic value. Name is returned in the format acceptable by functions demanding IP as input parameter.
- procedure GetSins
Actualize values in LocalSin and RemoteSin.
- function GetLocalSinIP:string
Picks IP socket address from LocalSin.
- function GetRemoteSinIP:string
Picks IP socket address from RemoteSin.
- function GetLocalSinPort:integer
Picks socket PORT number from LocalSin.
- function GetRemoteSinPort:integer
Picks socket PORT number from RemoteSin.