Example (EDG-4508+U):
SOCKADDR_IN HostAddr; SOCKET HostSock; SOCKADDR_IN ClntAddr; SOCKET ClntSock;
int ClntAddrLen; char RxData[256];
memset(&HostAddr, 0, sizeof(SOCKADDR_IN)); HostAddr..sin_family = AF_INET; HostAddr..sin_addr.s_addr = INADDR_ANY; HostAddr.sin_port = htons(5201);
//Define the TCP port of host PC. It's the same as the value that you key- in it in the "Peer for Receiving Data" item of configuration utility//
HostSock = socket(AF_INET, SOCK_STREAM, 0);
//Create the socket of TCP on the Host// bind(HostSock,(sockaddr *)&HostAddr, sizeof(HostAddr)); listen(HostSock, 1); ClntAddrLen=sizeof(ClntAddr);
ClntSock = accept(HostSock, (sockaddr *)&ClntAddr, &ClntAddrLen);
//The host PC accepts the connection request from the
recv(ClntSock, RxData, 256, 0);
//Receive the data from the port of
//Disconnect from the
70 |