- 论坛徽章:
- 0
|
大大们好,最近在做毕设,关于一个udp并发服务器模型的实现中有一个小小的疑问。
先看代码(代码太多,粘贴不过来,见附件,大大们谅解。。。)
其实不完全是实现的服务器,客户端模型,用到管道的那一块和毕设的 内容有关,大家只看 网络通信的那一块就好。呵呵。。。
本人有一个疑问,就是代码中明确表示出的两个socket。
do{ //comumunicate with client through new socket
if ( recvfrom(sockfd, msg, MAXLINE, 0,
(struct sockaddr *)&newfrom_addr, &newfrom_addr) < 0 ){
perror("recvfrom error");
} |
again:
recvlen = recvfrom(global_sockfd, msg, MAXLINE,
0,(struct sockaddr *) &global_from_addr, &len);
if(recvlen < 0 ){
perror("recvfrom error");
}
if(flag == 1){
if (srv_addr.sin_port == global_from_addr.sin_port)
printf("first connect from port:%d\n",ntohs(global_from_addr.sin_port));
srv_info.sin_port = global_from_addr.sin_port;
flag = 0;
}else{ // N connect (N >1)
if (port_hash_search(&global_from_addr) == 0){//hash port search
printf("connect time %d from port:%d\n",++count,
ntohs(global_from_addr.sin_port));
port_hash_add(&srv_addr);
//setup newsrv
start_newsrv(global_from_addr,msg);
}
goto again;
}
|
当新的udp srv socket已经生成,当udp客户端 发送来数据后,具体是 哪一个 recvfrom 先返回呢?
我要让sockfd只是接管数据接收,但global socket只是地址的hash,具体还可以怎么实现呢?大大们帮帮忙吧?
ps:代码已经编译通过了,大大们可以看看
[ 本帖最后由 wpclub 于 2009-4-27 09:24 编辑 ] |
|