其他函数请查看库源码。
一般不需要直接使用这些库函数。
应改用 wsock.tcp.client 或 wsock.udp.client 等库
Ws2_32.api("WSAAsyncSelect","int(POINTER s,int hwnd,int Message,int event)");
Ws2_32.api("__WSAFDIsSet","int(POINTER s,struct& passed_set)");
Ws2_32.api("WSAIoctl","int(POINTER s,INT dwIoControlCode, struct lpvInBuffer,INT cbInBuffer, struct lpvOutBuffer,INT cbOutBuffer,INT & lpcbBytesReturned, pointer lpOverlapped, pointer lpCompletionRoutine )");
_INVALID_HANDLE_VALUE;
创建一个新的套接字来与客户套接字创建连接通道,
如果连接成功,就返回新创建的套接字句柄
Ws2_32.api("bind","int(POINTER s, struct name,int namelen)" );
与wsock.open()配对使用,
使用wsock库以后必须调用此函数释放资源,
如果忘记配对调用此函数,在线程结束时将自动调用
Ws2_32.api("closesocket","int(POINTER s)");
Ws2_32.api("connect","int(POINTER s,struct& sockstruct,int structlen)");
获取空闲服务端口,
可选在参数中指定IP地址,其他参数不必指定
分配的端口即使没有马上使用,
系统下次分配的空闲端口仍然是递增分配下一个端口号,
动态分配空闲端口为49152到65535之间的值,
XP系统则为 1025到5000之间的值,
命令行输入 netsh int ipv4 show dynamicport tcp 看动态端口范围,
安装 Hyper-V 会导致动态起始端口变为 1024 导致常用端口冲突
解析域名,可返回一个或多个IP
如果不指定任何参数,返回内网IP,
优先取192.168.1 开头的IP,请改用 wsock.getLocalIp 函数,
如果要更优先获取当前上网卡的本机IP,
请改用 wsock.tcp.client.getLocalIp 函数
解析域名,
返回in_addr或in_addr结构体数组
返回值2为AF_INET或AF_INET6
返回内网IP,优先取192.168.1 开头的IP,
如果要更优先获取当前上网卡的本机IP,
请改用 wsock.tcp.client.getLocalIp 函数
Ws2_32.api("gethostbyaddr","pointer(string addr,int length,int thetype)")
Ws2_32.api("gethostbyname","pointer(string szHost)" );
Ws2_32.api("gethostname","int(str &szHost,int len)" );
Ws2_32.api("getpeername","int(POINTER s,struct& sockaddr,int& len)")
Ws2_32.api("getsockname","int(POINTER s,struct& sockaddr,int& len)")
Ws2_32.api("getsockopt","int(POINTER s,int level,int optname,struct&optval,int& optlen)")
Ws2_32.api("getsockopt","int(POINTER s,int level,int optname,int&optval,int& optlen)")
记录主机信息的结构体
Ws2_32.api("htonl","INT(INT hostlong)");
Ws2_32.api("htons","WORD(WORD hostshort)" );
IPv6 地址结构
创建 in_addr 结构体,表示 IPv4 地址。
返回值可用 tostring 函数转换为字符串,
可用 tonumber 函数转换为数值,Ipv4 实际存为 32 位整数。
Ws2_32.api("inet_addr","INT(string s)");
in_addr 结构体或数值转换为字符串格式 IP 地址
Ws2_32.api("ioctlsocket","int(POINTER s,int cmd, INT &argp)")
Ws2_32.api("listen","int(POINTER s,int backlog)");
Ws2_32.api("ntohl","INT(INT netlong)");
Ws2_32.api("ntohs","WORD(WORD netshort)");
使用wsock库其他函数以前必须调用此函数
Ws2_32.api("recv","int(POINTER s,string& buf,int len,int flags)" );
Ws2_32.api("recv","int(POINTER s,BYTE& b,int len,int flags)");
Ws2_32.api("recvfrom","int(POINTER s,string& Buf,int length,int flags, struct& sad, int& fromlen)")
所有参数可选,
成功返回套接字数目,超时返回0,出错返回-1/*_SOCKET_ERROR*/
Ws2_32.api("send","int(POINTER s,string msg,int msglen,int flag)");
Ws2_32.api("sendto","int(POINTER s,pointer Buf,int length,int flags, struct& sad, int& tolen)")
Ws2_32.api("setsockopt","int(POINTER s,word level,word optname,struct optval,int optlen)")
Ws2_32.api("setsockopt","int(POINTER s,word level,word optname,int& optval,int optlen)")
Ws2_32.api("shutdown","int(POINTER s,int how)")
字符串转换为 sockaddr_in 或 sockaddr_in6 结构体
字符串转换为 sockaddr_in 或 sockaddr_in6 结构体。
参数 @1 可指定 IPV4 或 IPV6 地址,可选包含端口号。
可选用参数 @2 指定端口号
sockaddr 指针或结构体转字符串
sockaddr 转字符串。
@sockaddr 可指定sockaddr 指针或结构体。
size 指定参数 @1 指向的内存长度。
@protocolInfo 不必指定
返回 sockaddr_in 结构体,所有参数可选。
参数 @1 可以使用域名、IP、数值,
如果参数 @1 是字符串,可在 IP 或域名后指定端口号。
如果参数 @1 传入 sockaddr_in 则直接返回该结构体。
参数错误返回 null 。
返回结构体可用 tostring 函数转为字符串,
也可以用 tonumber 转换为数值。
返回sockaddr_in6结构体,所有参数可选
参数@1可以使用域名、IPv6地址,
如果IPv6地址包含端口号,IPv6地址应置于中括号内部,
域名后不允许指定端口号
如果参数@1传入sockaddr_in6则直接返回该结构体
参数错误返回null
Ws2_32.api("socket","pointer(int af,int type,int protoco)" );
支持的版本,
用于在open函数中WSAStartup的第一个参数
16个8位字节数组
8个16位字数组
S_addr
s_b1
s_b2
s_b4
s_w1
s_w2
地址
IPv6地址类型,
值为_AF_INET6
IPv6的流信息
端口
标识地址范围
地址
IPv4地址类型,
值为_AF_INET
端口
对齐数据
AcceptEx
ConnectEx
DisconnectEx
EnumProtocols
FreeAddrInfoEx
FreeAddrInfoW
GetAcceptExSockaddrs
GetAddrInfoEx
GetAddrInfoExCancel
GetAddrInfoExOverlappedResult
GetAddrInfoW
GetAddressByName
GetHostNameW
GetNameByType
GetNameInfoW
GetService
GetTypeByName
InetNtop
InetPton
RIOCloseCompletionQueue
RIOCreateCompletionQueue
RIOCreateRequestQueue
RIODequeueCompletion
RIODeregisterBuffer
RIONotify
RIOReceive
RIOReceiveEx
RIORegisterBuffer
RIOResizeCompletionQueue
RIOResizeRequestQueue
RIOSend
RIOSendEx
SetAddrInfoEx
SetService
SetSocketMediaStreamingMode
TransmitFile
TransmitPackets
WSAAccept
WSAAddressToString
WSAAsyncGetHostByAddr
WSAAsyncGetHostByName
WSAAsyncGetProtoByName
WSAAsyncGetProtoByNumber
WSAAsyncGetServByName
WSAAsyncGetServByPort
WSAAsyncSelect
WSACancelAsyncRequest
WSACancelBlockingCall
WSACleanup
WSACloseEvent
WSAConnect
WSAConnectByList
WSAConnectByName
WSACreateEvent
WSADeleteSocketPeerTargetName
WSADuplicateSocket
WSAEnumNameSpaceProviders
WSAEnumNameSpaceProvidersEx
WSAEnumNetworkEvents
WSAEnumProtocols
WSAEventSelect
__WSAFDIsSet
WSAGetLastError
WSAGetOverlappedResult
WSAGetQOSByName
WSAGetServiceClassInfo
WSAGetServiceClassNameByClassId
WSAHtonl
WSAImpersonateSocketPeer
WSAInstallServiceClass
WSAIoctl
WSAIsBlocking
WSAJoinLeaf
WSALookupServiceBegin
WSALookupServiceEnd
WSALookupServiceNext
WSANSPIoctl
WSANtohl
WSAPoll
WSAProviderConfigChange
WSAQuerySocketSecurity
WSARecv
WSARecvDisconnect
WSARecvEx
WSARecvFrom
WSARecvMsg
WSARemoveServiceClass
WSAResetEvent
WSARevertImpersonation
WSASend
WSASendDisconnect
WSASendMsg
WSASendTo
WSASetBlockingHook
WSASetEvent
WSASetLastError
WSASetService
WSASetSocketPeerTargetName
WSASetSocketSecurity
WSASocket
WSAStartup
WSAStringToAddress
WSAUnhookBlockingHook
WSAWaitForMultipleEvents
accept
bind
closesocket
connect
freeaddrinfo
gai_strerror
getaddrinfo
gethostbyaddr
gethostbyname
gethostname
getipv4sourcefilter
getnameinfo
getpeername
getprotobyname
getprotobynumber
getservbyname
getservbyport
getsockname
getsockopt
getsourcefilter
htond
htonf
htonl
htonll
inet_addr
inet_ntoa
ioctlsocket
listen
ntohd
ntohf
ntohl
ntohll
recv
recvfrom
select
send
sendto
setipv4sourcefilter
setsockopt
setsourcefilter
shutdown
socket
描述
支持的最高版本
单进程可打开的最大套接字数
最大数据包大小,0为无限制
状态和配置
版本
文件句柄数组
文件句柄数
设置文件描述符,成功返回对象自身
Ws2_32.dll在wsock支持库中加载
_AF_APPLETALK=0x10
_AF_CCITT=0xA
_AF_CHAOS=5
_AF_DATAKIT=9
_AF_DECNET=0xC
_AF_DLI=0xD
_AF_ECMA=8
_AF_HYLINK=0xF
_AF_IMPLINK=3
_AF_INET=2
_AF_INET6=23
_AF_ISO=7
_AF_LAT=0xE
_AF_MAX=0x12
_AF_NETBIOS=0x11
_AF_NS=6
_AF_OSI=7
_AF_PUP=4
_AF_SNA=0xB
_AF_UNIX=1
_AF_UNSPEC=0x0
_FD_ACCEPT=8
_FD_CLOSE=0x20
_FD_CONNECT=0x10
_FD_OOB=4
_FD_READ=1
_FD_SETSIZE=0x40
_FD_WRITE=2
_FIOASYNC=0x8004667D
_FIONBIO=0x8004667E
_FIONREAD=0x8004667F
_HOST_NOT_FOUND=0x2AF9
_IMPLINK_HIGHEXPER=0x9E
_IMPLINK_IP=0x9B
_IMPLINK_LOWEXPER=0x9C
_INADDR_ANY=0x0
_INADDR_BROADCAST=-1
_INADDR_LOOPBACK=0x7F000001
_INADDR_NONE=-1
_IN_CLASSA_HOST=0xFFFFFF
_IN_CLASSA_MAX=0x80
_IN_CLASSA_NET=0xFF000000
_IN_CLASSA_NSHIFT=0x18
_IN_CLASSB_HOST=0xFFFF
_IN_CLASSB_MAX=0x10000
_IN_CLASSB_NET=0xFFFF0000
_IN_CLASSB_NSHIFT=0x10
_IN_CLASSC_HOST=0xFF
_IN_CLASSC_NET=0xFFFFFF00
_IN_CLASSC_NSHIFT=8
_IOCPARM_MASK=0x7F
_IOC_IN=0x80000000
_IOC_INOUT=0xC0000000
_IOC_OUT=0x40000000
_IOC_VOID=0x20000000
_IPPORT_BIFFUDP=0x200
_IPPORT_CMDSERVER=0x202
_IPPORT_DAYTIME=0xD
_IPPORT_DISCARD=9
_IPPORT_ECHO=7
_IPPORT_EFSSERVER=0x208
_IPPORT_EXECSERVER=0x200
_IPPORT_FINGER=0x4F
_IPPORT_FTP=0x15
_IPPORT_HTTP=0x50
_IPPORT_LOGINSERVER=0x201
_IPPORT_MTP=0x39
_IPPORT_NAMESERVER=0x2A
_IPPORT_NETSTAT=0xF
_IPPORT_RESERVED=0x400
_IPPORT_RJE=0x4D
_IPPORT_ROUTESERVER=0x208
_IPPORT_SMTP=0x19
_IPPORT_SUPDUP=0x5F
_IPPORT_SYSTAT=0xB
_IPPORT_TELNET=0x17
_IPPORT_TFTP=0x45
_IPPORT_TIMESERVER=0x25
_IPPORT_TTYLINK=0x57
_IPPORT_WHOIS=0x2B
_IPPORT_WHOSERVER=0x201
_IPPROTO_AH=0x33
_IPPROTO_CBT=7
_IPPROTO_DSTOPTS=0x3C
_IPPROTO_EGP=8
_IPPROTO_ESP=0x32
_IPPROTO_FRAGMENT=0x2C
_IPPROTO_GGP=3
_IPPROTO_HOPOPTS=0x0
_IPPROTO_ICLFXBM=0x4E
_IPPROTO_ICMP=1
_IPPROTO_ICMPV6=0x3A
_IPPROTO_IDP=0x16
_IPPROTO_IGMP=2
_IPPROTO_IGP=9
_IPPROTO_IPV4=4
_IPPROTO_IPV6=0x29
_IPPROTO_L2TP=0x73
_IPPROTO_MAX=0x100
_IPPROTO_ND=0x4D
_IPPROTO_NONE=0x3B
_IPPROTO_PGM=0x71
_IPPROTO_PIM=0x67
_IPPROTO_PUP=0xC
_IPPROTO_RAW=0xFF
_IPPROTO_RDP=0x1B
_IPPROTO_RESERVED_IPSEC=0x102
_IPPROTO_RESERVED_IPSECOFFLOAD=0x103
_IPPROTO_RESERVED_MAX=0x104
_IPPROTO_RESERVED_RAW=0x101
_IPPROTO_ROUTING=0x2B
_IPPROTO_SCTP=0x84
_IPPROTO_ST=5
_IPPROTO_TCP=6
_IPPROTO_UDP=0x11
_IP_OPTIONS=1
_MSG_DONTROUTE=4
_MSG_MAXIOVLEN=0x10
_MSG_OOB=1
_MSG_PEEK=2
_NO_ADDRESS=0x2AFC
_NO_DATA=0x2AFC
_NO_RECOVERY=0x2AFB
_PF_APPLETALK=0x10
_PF_CCITT=0xA
_PF_CHAOS=5
_PF_DATAKIT=9
_PF_DECNET=0xC
_PF_DLI=0xD
_PF_ECMA=8
_PF_HYLINK=0xF
_PF_IMPLINK=3
_PF_INET=2
_PF_ISO=7
_PF_LAT=0xE
_PF_MAX=0x12
_PF_NETBIOS=0x11
_PF_NS=6
_PF_OSI=7
_PF_PUP=4
_PF_SNA=0xB
_PF_UNIX=1
_PF_UNSPEC=0x0
_SIO_ABSORB_RTRALERT=0x98000005
_SIO_INDEX_ADD_MCAST=0x9800000A
_SIO_INDEX_BIND=0x98000008
_SIO_INDEX_DEL_MCAST=0x9800000B
_SIO_INDEX_MCASTIF=0x98000009
_SIO_KEEPALIVE_VALS=0x98000004
_SIO_LIMIT_BROADCASTS=0x98000007
_SIO_RCVALL=0x98000001
_SIO_RCVALL_IF=0x9800000E
_SIO_RCVALL_IGMPMCAST=0x98000003
_SIO_RCVALL_MCAST=0x98000002
_SIO_RCVALL_MCAST_IF=0x9800000D
_SIO_UCAST_IF=0x98000006
_SOCKET_ERROR=-1
_SOCK_DGRAM=2
_SOCK_ERROR=-1
_SOCK_RAW=3
_SOCK_RDM=4
_SOCK_SEQPACKET=5
_SOCK_STREAM=1
_SOL_SOCKET=0xFFFF
_SOMAXCONN=5
_SO_ACCEPTCON=2
_SO_BROADCAST=0x20
_SO_DEBUG=1
_SO_DONTLINGER=0xFFFFFF7F
_SO_DONTROUTE=0x10
_SO_ERROR=0x1007
_SO_KEEPALIVE=8
_SO_LINGER=0x80
_SO_OOBINLINE=0x100
_SO_RCVBUF=0x1002
_SO_RCVLOWAT=0x1004
_SO_RCVTIMEO=0x1006
_SO_REUSEADDR=4
_SO_SNDBUF=0x1001
_SO_SNDLOWAT=0x1003
_SO_SNDTIMEO=0x1005
_SO_TYPE=0x1008
_SO_USELOOPBACK=0x40
_TCP_NODELAY=1
_TRY_AGAIN=0x2AFA
_WSABASEERR=0x2710
_WSADESCRIPTION_LEN=0x100
_WSAHOST_NOT_FOUND=0x2AF9
_WSAIOW=_WSAIOW=function(x,y) {return (0x80000000
_WSANO_ADDRESS=0x2AFC
_WSANO_DATA=0x2AFC
_WSANO_RECOVERY=0x2AFB
_WSASYS_STATUS_LEN=0x80
_WSATRY_AGAIN=0x2AFA