SYNAPSE - Synchronous TCP/IP Library for Delphi
Other related information can be found at http://www.mlp.cz/space/gebauerl/synapse/
Class: TUDPBlockSocket
- 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.
- 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.
- procedure SendBuffer(buffer:pointer;length:integer)
Sends data of LENGTH from BUFFER address via connected socket. System automatically splits data to packets.
- procedure SendBufferTo(buffer:pointer;length:integer)
Same as SendBuffer, but send datagram to address from RemoteSin. Usefull for sending reply to datagram received by function RecvBufferFrom.
- function RecvBuffer(buffer:pointer;length:integer):integer
Receives first waiting datagram to allocated buffer. If there is no waiting one, then waits until one comes. Returns length of datagram stored in BUFFER. If length exceeds buffer datagram is truncated.
- function RecvBufferFrom(buffer:pointer;length:integer):integer
Same as RecvBuffer, but RemoteSin is filled by sender of received datagram.
- function PeekBuffer(buffer:pointer;length:integer):integer
Same as RecvBuffer, but readed data stays in input buffer.
- function WaitingData:integer
Returns length of the first waiting datagram. Returns 0 if no datagram is waiting.
- function CanRead(Timeout:integer):boolean
Return TRUE, if you can from socket read any data. Status is tested for time Timeout (seconds). 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 (seconds). 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.
- 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.