Description | Hierarchy | Fields | Methods | Properties |
type unaSocket = class(unaObject)
Base class implementing Windows socket.
constructor create(); overload; |
|
constructor create(socket: tSocket; addressFamily, socketProtocol, socketType: int; const addr: sockaddr_in; len: int); overload; |
|
destructor Destroy(); override; |
|
function accept(out socket: tSocket; timeout: tTimeout = tTimeout(INFINITE)): unaSocket; |
|
function bind(addr: pSockAddrIn = nil): int; virtual; |
|
function bindSocketToPort(port: int = -1): int; |
|
function check_error(timeout: tTimeout = 0): bool; |
|
function close(graceful: bool = true): int; |
|
function connect(addr: pSockAddrIn = nil): int; |
|
class function getGeneralMTU(): uint; |
|
function getMTU(): uint; |
|
function getOptBool(opt: int): bool; |
|
function getOptInt(opt: int): int; |
|
function getPendingDataSize(noCheckState: bool = false): uint; |
|
function getPort(): string; |
|
function getPortInt(): word; |
|
function getSockAddr(out addr: sockaddr_in): int; |
|
function getSockAddrBound(out addr: sockaddr_in): int; |
|
function getSocket(forceCreate: bool = false): tSocket; |
|
function isConnected(timeout: tTimeout = 0): bool; |
|
function isListening(): bool; |
|
function listen(backlog: int = SOMAXCONN): int; |
|
function okToRead(timeout: tTimeout = 0; noCheckState: bool = false): bool; |
|
function okToWrite(timeout: tTimeout = 0; noCheckState: bool = false): bool; |
|
function read(const buf: pointer; var size: uint; timeout: tTimeout = tTimeout(INFINITE); noCheck: bool = false): int; |
|
function readString(noCheck: bool = false): aString; |
|
function send(const value: aString; noCheck: bool = false): int; overload; |
|
function send(buf: pointer; size: uint; noCheck: bool = false): int; overload; |
|
function setOptBool(opt: int; value: bool): int; |
|
function setOptInt(opt: int; value: int): int; |
|
function setPort(port: word; noCheck: bool = false): bool; overload; |
|
function setPort(const port: string; noCheck: bool = false): bool; overload; |
|
function shutdown(how: int): int; |
|
function waitForData(timeout: tTimeout = tTimeout(INFINITE); noCheckState: bool = false): bool; |
|
function closeSocket(): int; virtual; |
|
function ioctl(command: uint; var param: int32): int; virtual; |
|
procedure setHost(const host: string); |
property addressFamily: int read f_addressFamily; |
|
property bindToIP: string read f_bindToIP write setBindToIP; |
|
property bindToPort: string read getBindToPort write setBindToPort; |
|
property handle: tSocket read f_socket; |
|
property host: string read f_host write setHost; |
|
property isActive: bool read getIsActive; |
|
property rcvBufSize: uint read getBufSizeRcv write setBufSizeRcv; |
|
property sndBufSize: uint read getBufSizeSnd write setBufSizeSnd; |
|
property socketProtocol: int read f_socketProtocol; |
|
property socketType: int read f_socketType; |
constructor create(); overload; |
|
Initializes the socket. Parameters
|
constructor create(socket: tSocket; addressFamily, socketProtocol, socketType: int; const addr: sockaddr_in; len: int); overload; |
|
Initializes the socket. This constructor is mostly used by TCP server with sockets handle returned by accept().
Parameters
|
destructor Destroy(); override; |
|
Closes and destroys the socket. |
function accept(out socket: tSocket; timeout: tTimeout = tTimeout(INFINITE)): unaSocket; |
|
Blocks until new connection will be established with socket, or timeout value expires. NOTE: this method should be used with TCP sockets only.
Parameters
ReturnsNew connected client socket, or nil if timeout or error occur. |
function bind(addr: pSockAddrIn = nil): int; virtual; |
|
Binds a socket to local address.
Parameters
Returns0 if successfull, or specific WSA error. |
function bindSocketToPort(port: int = -1): int; |
|
Binds the socket to specified port. If port value is -1 (default), this function uses the bindToPort property as a port number to bind to. If port value is 0, this function auto-assigns first available port number for socket. Returns0 if successfull (or socket is not connected/listening), or specific WSA error. |
function check_error(timeout: tTimeout = 0): bool; |
|
Checks if there is some error with socket.
Parameters
ReturnsTrue if there are some error. |
function close(graceful: bool = true): int; |
|
Closes the socket.
Parameters
Returns0 if successfull (or socket was not connected/listening), or specific WSA error. |
function connect(addr: pSockAddrIn = nil): int; |
|
Connects the socket to remote host.
Parameters
Returns0 if socket has been connected successfully or specific WSA error. |
class function getGeneralMTU(): uint; |
|
Returns maximum transmission unit (MTU) size. NOTE: this value should not be used as real MTU size, but only as an estimation for most cases. |
function getMTU(): uint; |
|
Returns maximum transmission unit (MTU) size for connected socket. |
function getOptBool(opt: int): bool; |
|
Returns boolean option of the socket. |
function getOptInt(opt: int): int; |
|
Returns integer option of the socket. |
function getPendingDataSize(noCheckState: bool = false): uint; |
|
Returns number of bytes available to read from socket. |
function getPort(): string; |
|
Returns remote port value as string. |
function getPortInt(): word; |
|
Returns remote port value as word. |
function getSockAddr(out addr: sockaddr_in): int; |
|
Returns sockaddr_in structure filled with address:port values which corresponds to the socket.
Parameters
Returns0 if successfull, or a specific WSA error. |
function getSockAddrBound(out addr: sockaddr_in): int; |
|
Returns sockaddr_in structure filled with address:port values which corresponds to the bound socket. Do not use if socket is not bound yet.
Parameters
Returns0 if successfull, or a specific WSA error. |
function getSocket(forceCreate: bool = false): tSocket; |
|
Returns socket handle.
Parameters
ReturnsSocket handle (or INVALID_SOCKET if socket was not created or was closed and forceCreate is False). |
function isConnected(timeout: tTimeout = 0): bool; |
|
Checks if socket is connected.
Parameters
ReturnsTrue if socket is connected to remote host, and there was no error. |
function isListening(): bool; |
|
Checks if socket is listening.
Parameters
ReturnsTrue if socket is listening, and there was no error. |
function listen(backlog: int = SOMAXCONN): int; |
|
Binds the socket to specified port and starts listening for incoming connections.
Parameters
Returns0 if successfull (or socket is already listening), or specific WSA error. |
function okToRead(timeout: tTimeout = 0; noCheckState: bool = false): bool; |
|
Checks if it is OK to read data from socket now.
Parameters
ReturnsTrue if there are some chances data could be read now. |
function okToWrite(timeout: tTimeout = 0; noCheckState: bool = false): bool; |
|
Checks if it is OK to write data into socket now.
Parameters
ReturnsTrue if there are some chances data could be send now. |
function read(const buf: pointer; var size: uint; timeout: tTimeout = tTimeout(INFINITE); noCheck: bool = false): int; |
|
Reads data from socket.
Parameters
ReturnsOtherwise returns some specific WSA error. |
function readString(noCheck: bool = false): aString; |
|
Reads a string from socket. |
function send(const value: aString; noCheck: bool = false): int; overload; |
|
Sends string of bytes over socket.
Parameters
Returns0 if sent operation done was OK, or specific WSA error. |
function send(buf: pointer; size: uint; noCheck: bool = false): int; overload; |
|
Sends data over socket.
Parameters
Returns0 if sent operation was OK, or specific WSA error. |
function setOptBool(opt: int; value: bool): int; |
|
Sets boolean option of the socket. |
function setOptInt(opt: int; value: int): int; |
|
Sets integer option of the socket. |
function setPort(port: word; noCheck: bool = false): bool; overload; |
|
Sets remote port number for the socket to connect to. |
function setPort(const port: string; noCheck: bool = false): bool; overload; |
|
Sets remote port for the socket to connect to. |
function shutdown(how: int): int; |
|
Shuts down the socket. Call close() to clean up the socket before reusing it again.
Parameters
Returns0 if successfull (or socket was not connected/listening), or specific WSA error. |
function waitForData(timeout: tTimeout = tTimeout(INFINITE); noCheckState: bool = false): bool; |
|
Waits until data will be available to read from socket or timeout expire. |
function closeSocket(): int; virtual; |
|
Closes the socket. Returns0 if successfull (or socket was not created), or specific WSA error. |
function ioctl(command: uint; var param: int32): int; virtual; |
|
Issues an IOCTL command on a socket.
Parameters
Returns0 if successfull, or specific WSA error. |
procedure setHost(const host: string); |
|
Sets remote host address/DNS name. Does nothing if socket is active (connected/listening). |
property addressFamily: int read f_addressFamily; |
|
Specifies socket address family. For most applications you should use the AF_INET value. Other possible values: AF_INET/AF_NETBIOS/AF_INET6/AF_IRDA/AF_BTM |
property bindToIP: string read f_bindToIP write setBindToIP; |
|
Specifies IP address the socket should bind to. Default value means the socket will bind to any availabe interface. |
property bindToPort: string read getBindToPort write setBindToPort; |
|
Specifies Port name or number the socket should bind to. Default value (0) means the socket will bind to first availabe port number. Client sockets should always be bind to default port (0), unless you need some special behaviour. |
property handle: tSocket read f_socket; |
|
Socket handle. |
property host: string read f_host write setHost; |
|
Specifies remote host value for the socket. This value will be used to connect socket to. |
property isActive: bool read getIsActive; |
|
Returns True is socket is TCP server socket and is listening, or if socket is TCP client and is connected, or if socket is bind to UDP port/interface. Otherwise returns false. |
property rcvBufSize: uint read getBufSizeRcv write setBufSizeRcv; |
|
Size of receiving buffer. |
property sndBufSize: uint read getBufSizeSnd write setBufSizeSnd; |
|
Size of sending buffer. |
property socketProtocol: int read f_socketProtocol; |
|
Specifies protocol number to be used with socket (IPPROTO_TCP/UDP, etc.) |
property socketType: int read f_socketType; |
|
Specifies socket type to be used with socket (SOCK_STREAM/DGRAM, etc.) |
(c) 2012 Lake of Soft