本文主要是介绍TCP Socket通信CAPL代码演示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TCP通信过程分为三个部分:
- 建立连接:三次握手
- 数据传输
- 关闭连接:四次挥手
这些都可以通过socket套接字接口来实现。
Client:
variables
{const dword INVALID_SOCKET = 0xFFFFFFFF;dword clientSocket = INVALID_SOCKET;char rxBuffer[1500];
}on key 'a'
{clientSocket = tcpOpen(ipGetAddressAsNumber("192.168.0.52"), 6001);tcpConnect(clientSocket, ipGetAddressAsNumber("192.168.0.17"), 6002);
}void OnTcpConnect(dword socket, long result)
{if (result != 0)return;if (socket == clientSocket)write("Client: Connection Established");tcpReceive(clientSocket, rxBuffer, elcount(rxBuffer));
}on key 'b'
{tcpSend(clientSocket, "12345", 5);
}void OnTcpReceive(dword socket, long result, dword address, dword port, char buffer[], dword size)
{if (result != 0)return;if (socket =
这篇关于TCP Socket通信CAPL代码演示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!