Program Examples:TCP IP:TCPIP Simple Server/zh-hans
语言: | English • 中文(简体) |
---|
以下示例演示了一个简单的TCP-IP服务器的设置。
服务器打开一个套接字并阻止“Accept”,直到客户端连接。 然后发生一次消息交换后,服务器关闭连接并终止:
program 'continue
dim str1 as string
dim Test_str as string
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
Test_str="Server sending test string"
Accept(#1, 6001)
sleep 100
print #1,Test_str; 'send
sleep 200
str1=input$(loc(1),#1) 'receive
if str1 = "Client sending test string" then
?"server.prg test is successful"
else
?"server.prg test FAILED"
?str1
end if
sleep 200
close #1
Print "Server Closed Sockets. Server Exits"
end program
该示例对应于提交在GIT中的SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b。