Skip to content

Commit 0f7e989

Browse files
committed
加个tcp测试脚本
1 parent 09b50c7 commit 0f7e989

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/tcptest.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--调用c#接口进行tcp调试
2+
ipStr = "180.97.80.55"
3+
port = 12415
4+
sendStr = "hello server"
5+
6+
sys.taskInit(function ()
7+
tcpClient = CS.System.Net.Sockets.TcpClient(ipStr, port)
8+
stream = tcpClient:GetStream()
9+
while true do
10+
-- Send the message to the connected TcpServer.
11+
stream:Write(sendStr, 0, #sendStr)
12+
13+
print("Sent:", sendStr)
14+
15+
sys.wait(100)
16+
print("start recv", stream.CanRead)
17+
18+
local revT = {}
19+
while stream.DataAvailable do
20+
table.insert(revT,string.char(stream:ReadByte()))
21+
end
22+
local rev = table.concat(revT)
23+
print("receive",rev,#rev)
24+
end
25+
-- Close everything.
26+
stream:Close()
27+
tcpClient:Close()
28+
end)

0 commit comments

Comments
 (0)