udp srv: socket(); bind(port); while(1) { if(recvConnectReQ) { AfxBeginThread(taskThd); } if(StopEvent) break; } -------------- taskThd: socket(); bind(a unused port); send msg to the client socket: I am Here, u can cantact with me begin the task; closesocket(); -------------- udp client: socket(); bind(); sendConnectReq; if recved the I am Here msg, transmit data to that socket! task over;
UDP服务器端:
1.创建套接字
2.将套接字邦定到一个IP地址和端口
3.等待接收数据
4.关闭套接字
UDP客户端:
1.创建套接字
2.向服务器发送数据
3.关闭套接字
那这样的话是不是忙得过来啊?
再说如果一台机器上多个SOCKET怎么bind啊?
socket();
bind(port);
while(1)
{
if(recvConnectReQ)
{
AfxBeginThread(taskThd);
}
if(StopEvent)
break;
}
--------------
taskThd:
socket();
bind(a unused port);
send msg to the client socket: I am Here, u can cantact with me
begin the task;
closesocket();
--------------
udp client:
socket();
bind();
sendConnectReq;
if recved the I am Here msg, transmit data to that socket!
task over;