Difference between revisions of "Program Examples:TCP IP:TCPIP Multi Server/zh-hans"
(Created page with "{{Languages}} The following example demonstrates the set up of a TCP-IP server that opens connection with multiple clients. The server opens a socket and blocks on "Accept" u...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | {{Languages}} | + | {{Languages|Program_Examples:TCP_IP:TCPIP_Multi_Server}} |
− | + | 以下示例演示了建立与多个客户机打开连接的TCP-IP服务器。 | |
− | + | 服务器打开一个套接字并阻止"Accept",直到客户端连接。 然后发生消息交换,服务器关闭连接并再次被阻止等待接受下一个客户端。 | |
− | |||
<syntaxhighlight lang="vb"> | <syntaxhighlight lang="vb"> | ||
Line 60: | Line 59: | ||
− | + | 该示例对应于在GIT中的提交的SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b. | |
− | == | + | == 参见 == |
* [[Program Examples:TCP IP:TCPIP Simple Server|TCP/IP Simple Server]] | * [[Program Examples:TCP IP:TCPIP Simple Server|TCP/IP Simple Server]] | ||
* [[Program Examples:TCP IP:TCPIP Simple Client|TCP/IP Simple Client]] | * [[Program Examples:TCP IP:TCPIP Simple Client|TCP/IP Simple Client]] |
Latest revision as of 08:19, 16 July 2017
语言: | English • 中文(简体) |
---|
以下示例演示了建立与多个客户机打开连接的TCP-IP服务器。
服务器打开一个套接字并阻止"Accept",直到客户端连接。 然后发生消息交换,服务器关闭连接并再次被阻止等待接受下一个客户端。
program 'continue
dim str1 as string
dim Test_str as string
dim X as long = 20
Try
OpenSocket Options=1 as #1
catch 5043 'socket is already open
print "socket 1 is already open. closing an reopening"
close #1
OpenSocket Options=1 as #1
End Try
while 1
Try
OpenSocket Options=1 as #X
catch 5043 'socket is already open
print "socket 2 is already open. closing an reopening"
close #X
OpenSocket Options=1 as #X
End Try
Test_str="Server sending test string"
Accept(#1, #X, 6001)
sleep 100
print #X, Test_str; 'send
sleep 200
str1=input$(loc(X),#X) 'receive
if str1 = "Client sending test string" then
?"server.prg test is successful"
else
?"server.prg test FAILED"
?str1
end if
sleep 200
close #X
X = X + 1
end while
close #1
Print "Server Closed Sockets. Server Exits"
end program
该示例对应于在GIT中的提交的SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b.