logo资料库

CoDeSys_syslibsockets.pdf

第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
资料共13页,剩余部分请下载后查看
The Library SysLibSockets.lib
SysSockAccept
Structure SOCKADDR:
SysSockBind
SysSockClose
SysSockConnect
SysSockCreate
SysSockGetHostByName
SysSockGetHostName
SysSockGetOption
SysSockHtons
SysSockInetAddr
SysSockInetNtoa
Struktur INADDR:
SysSockIoctl
SysSockListen
SysSockNtohl
SysSockNtohs
SysSockSelect
Structure SOCKET_FD_SET
Structure SOCKET_TIMEVAL:
SysSockSetIPAddress
SysSockSetOption
SysSockShutdown
SysSockHtonl
TCP Specific Functions
SysSockRecv
SysSockSend
UDP Specific Functions
SysSockRecvFrom
SysSockSendTo
The Library SysLibSockets.lib The Library SysLibSockets.lib If the target system supports the functionality, this library supports the access on sockets for the communication via TCP_IP and UDP. The library functions each call the correspondent function of the currently used operating system. Therefore please see the help system of the currently used operating system for detailled information on the particular OS functions. The functions, arranged alphabetically: · SysSockAccept · SysSockBind · SysSockClose · SysSockConnect · SysSockCreate · SysSockGetHostByName · SysSockGetHostName · SysSockGetOption · SysSockHtonI · SysSockHtons · SysSockInetAddr · SysSockInetNtoa · SysSockloctl · SysSockListen · SysSockNtohI · SysSockNtohs · SysSockSelect · SysSockSetIPAddress · SysSockSetOption · SysSockShutdown TCP specific: · SysSockRecv, SysSockSend UDP specific: · SysSockRecvFrom, · SysSockSendTo © 3S – Smart Software Solutions GmbH / 16.12.2002 1
The Library SysLibSockets.lib SysSockAccept This function of type DINT calls the function accept of the operating system in order to accept a connection request to the socket. A new descriptor (handle) for the socket will be returned. The orignal socket will be reset to the "listening" status (see SysSockListen). Data type Description A descriptor identifying a socket that has been placed in a listening state with the SysSockListen function. The connection will actually be made with the socket that is returned by the SysSockListen function. The requested connection then will be made with that socket, for which the SysSockAccept function returns a handle. (corresponding parameter e.g. in Win32:s) Pointer to a variable of type SOCKADDR; will be filled with the address of the caller. (corresponding parameter e.g. in Win32: addr) Length of the structure SockAddr (can be retrieved via the SIZEOF operator) (corresponding parameter e.g. in Win32: addrlen) Variable diSocket DINT pSockAddr DWORD diSocketAddrSize DINT Structure SOCKADDR: INT; UINT; UDINT; ARRAY [0..7] OF SINT; sin_family : sin_port : sin_addr : sin_zero : (* Adress-family, defines address format, *) (* Port of the connection requesting unit *) (* IP-address of the requesting unit *) (* buffer *) SysSockBind This function of type BOOL calls the function bind of the operating system. This function will allocate a local address to the socket which was assigned before just to an address range by SysSockCreate. Usually the "binding" will be done before functions like SysSockListen or SysSockAccept are called for a socket. In case of successful operation the function will return TRUE, otherwise FALSE. Variable diSocket Data type Description DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) pSockAddr DWORD Pointer to a variable of type SOCKADDR; (see SysSockAccept) diSockAddrSize DINT Lenght of the structure SOCKADDR (can be retrieved with the aid of the SIZEOF operator) 2 © 3S – Smart Software Solutions GmbH / 16.12.2002
SysSockClose The Library SysLibSockets.lib This function of type BOOL calls the function closesocket of the operating system, in order to close a socket. In case of successful operation the function will return TRUE, otherwise FALSE. Variable diSocket Data type Description DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) SysSockConnect This function of type BOOL calls the function connect of the operating system. In case the socket has not yet been "bound" by the SysSockBind function (see above), now automatically a local address will be assigned to it. Afterwards the socket will be ready to send and /or receive data. In case of successful operation the function will return TRUE, otherwise FALSE. Variable diSocket Data type Description DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) pSockAddr DWORD Pointer auf eine Variable vom Typ SOCKADDR; (see SysSockAccept) diSockAddrSize DINT Length of the structure SOCKADDR (can be retrieved with the aid of the SIZEOF operator) SysSockCreate This function of type DINT calls the function socket of the operating system. A new socket will be created and assigned to a Service Provider. The function returns the descriptor of the new socket, which is used as input parameter in other functions of the library, e.g. SysSockBind, SysSockConnect. Variable Data type Description diAddressFamily DINT diType DINT Address family (corresponding parameter e.g. in Win32: af) One of the following two types can be used e.g. for Windows Sockets 1.1: SOCK_STREAM, SOCK_DGRAM (corresponding parameter e.g. in Win32: type) diProtocol DINT Protocol, depending on the chosen address family (corresponding parameter e.g. in Win32: protocol) © 3S – Smart Software Solutions GmbH / 16.12.2002 3
SysSockGetHostByName The Library SysLibSockets.lib This function of type DWORD calls the function hostGetByName (VxWorks) resp. gethostbyname (win32) of the operating system. In case of return SOCKET_INADDR_NONE (defined in the library as a global constant). successful operation the function will the host address, otherwise Variable Data type Description stHostName POINTER TO STRING Name of the host (corresponding parameter e.g. in Win32: name) SysSockGetHostName This function of type BOOL calls the function gethostname of the operating system auf and returns the host name. In case of successful operation the function will return TRUE, otherwise FALSE. Variable Data type Description stHostName STRING diNameLength DINT Host name (corresponding parameter e.g. in Win32: name) Length of the host name (corresponding parameter e.g. in Win32: buflen) SysSockGetOption This function of type BOOL calls the function getsockopt of the operating system, in order to get the value of a particular socket option. In case of successful operation the function will return TRUE, otherwise FALSE. Variable diSocket diLevel Data type Description DINT DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) protocol specific level; possible values: SOL_SOCKET, IPPROTO_TCP (corresponding parameter e.g. in Win32: level) diOption DINT Name of the option, for which you want to get the current value; see function SysSockSetOption for a list of the options (corresponding parameter e.g. in Win32: optname) 4 © 3S – Smart Software Solutions GmbH / 16.12.2002
The Library SysLibSockets.lib diOptionValue DWORD diOptionLength DWORD Pointer to the variable, to which the current value of the option should be written (corresponding parameter e.g. in Win32: optval) Pointer to the size of the variable, to which the current value of the option should be written (corresponding parameter e.g. in Win32: optlen) SysSockHtons This function of type WORD calls the function htons of the operating system, which converts a short value from host byte order to TCP/IP network order. The function returns the converted value. For a description of this function please see the Online Help resp. documentation on the operating system. Variable Data type Description wHost WORD Value to be converted. SysSockInetAddr This function of type DWORD calls the function inet_addr of the operating system, which converts a string containing an internet address to an address which can be used in the IN_ADDR structure. The function returns the converted address. Variable stIPAddr Data type Description STRING IP address (dotted notation) (corresponding parameter e.g. in Win32: cp) © 3S – Smart Software Solutions GmbH / 16.12.2002 5
The Library SysLibSockets.lib SysSockInetNtoa This function of type BOOL calls the function inet_ntoa (Win32) bzw. inet_ntoa_b (VxWorks), which converts an Internet network address to a string in Internet standard format.. In case of successful operation the function will return TRUE, otherwise FALSE. Variable Data type Description pInAddr INADDR Pointer to structure INADDR, which contains the Internet address, see below (corresponding parameter e.g. in Win32: in) stIPAddr STRING IP address diIPAddrSize DINT Size of the IP address Struktur INADDR: S_addr : DWORD; (* Internet-Adresse als DWORD *) This function of type DINT calls the function ioctl of the operating system in order to control the I/O mode of the socket. In case of successful operation the function will return TRUE, otherwise FALSE. Variable Data type Description diSocket DINT diCommand DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) Command which you want to apply on the socket. (corresponding parameter e.g. in Win32: cmd). Valid commands are: SOCKET_FIONBIO, SOCKET_FIONREAD. piParameter DWORD Pointer to the command parameter (corresponding parameter e.g. in Win32: argp SysSockIoctl 6 © 3S – Smart Software Solutions GmbH / 16.12.2002
The Library SysLibSockets.lib SysSockListen This function of type BOOL calls the function listen of the operating system. This function will cause the socket to listen to connection requests and to queue them until they can be accepted by the SysSocketAccept function. In case of successful operation the function will return TRUE. As soon as the maximum number of connection requests in the queue is exceeded the function will return FALSE. Variable diSocket Data type Description DINT Descriptor of the socket, returned by SysSockCreate (corresponding parameter e.g. in Win32: s) diMaxConnections DINT Maximum number of connection requests, which can be put in the input queue of the socket. (corresponding parameter e.g. in Win32: backlog) SysSockNtohl SysSockNtohs This function of type DWORD calls the function ntohl of the operating system, which converts a u_long value of the TCP/IP network order to the host byte order. The function will return the value in host byte order. Variable dwNet Data type Description DWORD u_long value to be converted (corresponding parameter e.g. in Win32: netlong) This function of type WORD calls the function ntohs of the operating system, which converts a u_short value from the TCP/IP network order to the host byte order. The function will return the value in host byte order. Variable wNet Data type Description WORD u_short value to be converted (corresponding parameter e.g. in Win32: netshort © 3S – Smart Software Solutions GmbH / 16.12.2002 7
SysSockSelect The Library SysLibSockets.lib This function of type BOOL calls the function select of the operating system to check whether one or several sockets are ready for certain communication actions. The group of sockets, to which this request should be applied, can be defined via the structure SOCKET_FD_SET. The function will return the result of the select function. Variable Data type Description diWidth fdRead DINT DWORD fdWrite DWORD fdExcept DWORD ptvTimeout DWORD Size of structure SOCKET_FD_SET. Optionally a pointer to the structure defining the socket set for which the status of the read actions should be checked. You also can pass 0. Structure SOCKET_FD_SET see below (corresponding parameter e.g. in Win32: readfds) Optionally a pointer to the structure, defining the socket for which the status of the write actions should be checked. You also can pass 0. Structure SOCKET_FD_SET see below (corresponding parameter e.g. in Win32: writefds) Optionally a pointer to the structure, defining the socket for which the error status should be checked. You also can pass 0. Structure SOCKET_FD_SET see below (corresponding parameter e.g. in Win32: exceptfds) Maximum time which the SysSockSelect function will wait for an answer; Structure SOCKET_TIMEVAL, see below (corresponding parameter e.g. in Win32:timeout) Structure SOCKET_FD_SET fd_count: UDINT; (* Number of sockets *) fd_array: ARRAY [0..63] OF DINT; (* Field with socket descriptors *) Structure SOCKET_TIMEVAL: tv_sec: tv_usec: DINT; DINT; (* seconds *) (* microseconds *) 8 © 3S – Smart Software Solutions GmbH / 16.12.2002
分享到:
收藏