当前位置: 技术问答>linux和unix
求救:Socket 通讯出现混乱,求网络编程高手!!!!!!
来源: 互联网 发布时间:2016-03-16
本文导语: 在服务器上的代码结构如下: ////////////////////////////////////////////////////////////////////// // File name: network_Srv.c // ////////////////////////////////////////////////////////////////////// vo...
在服务器上的代码结构如下:
//////////////////////////////////////////////////////////////////////
// File name: network_Srv.c //
//////////////////////////////////////////////////////////////////////
void GeneralCmdSrv()
{
SOCKET sockCmdListen = -1;
SOCKET sockCmdSvr = -1;
struct sockaddr_in addr;
restart:
sockCmdListen = socket(AF_INET, SOCK_STREAM, 0);
...
if ( bind( sockCmdListen, (PSA) &addr, sizeof(addr) ) 10.0.1.189.35000: P 1:7(6) ack 1 win 5840 (DF)
11:29:27.060660 10.0.1.189.35000 > 10.0.1.172.51121: . ack 7 win 8754
11:29:27.060723 10.0.1.189.35000 > 10.0.1.172.51121: P 1:21(20) ack 7 win 8760
11:29:27.060739 10.0.1.172.51121 > 10.0.1.189.35000: . ack 21 win 5840 (DF)
11:29:27.060751 10.0.1.189.35000 > 10.0.1.172.51121: F 21:21(0) ack 7 win 8760
11:29:27.060772 10.0.1.172.51121 > 10.0.1.189.35000: F 7:7(0) ack 22 win 5840 (DF)
11:29:27.060854 10.0.1.189.35000 > 10.0.1.172.51121: . ack 8 win 8760
11:29:27.090148 10.0.1.172.51122 > 10.0.1.189.35000: S 2489297045:2489297045(0) win 5840 (DF)
11:29:27.090556 10.0.1.189.35000 > 10.0.1.172.51122: S 2295442432:2295442432(0) ack 2489297046 win 8760
11:29:27.090564 10.0.1.172.51122 > 10.0.1.189.35000: . ack 1 win 5840 (DF)
11:29:27.090602 10.0.1.172.51122 > 10.0.1.189.35000: P 1:7(6) ack 1 win 5840 (DF)
11:29:27.090710 10.0.1.189.35000 > 10.0.1.172.51122: . ack 7 win 8754
11:29:27.090725 10.0.1.172.51122 > 10.0.1.189.35000: P 7:12(5) ack 1 win 5840 (DF)
11:29:27.090802 10.0.1.189.35000 > 10.0.1.172.51122: . ack 12 win 8755
11:29:27.093640 10.0.1.189.35000 > 10.0.1.172.51122: P 1:12(11) ack 12 win 8760
11:29:27.093667 10.0.1.189.35000 > 10.0.1.172.51122: F 12:12(0) ack 12 win 8760
11:29:27.093689 10.0.1.172.51122 > 10.0.1.189.35000: . ack 12 win 5840 (DF)
11:29:27.093700 10.0.1.172.51122 > 10.0.1.189.35000: F 12:12(0) ack 13 win 5840 (DF)
11:29:27.093799 10.0.1.189.35000 > 10.0.1.172.51122: . ack 13 win 8760
11:29:27.140139 10.0.1.172.51123 > 10.0.1.189.35000: S 2493355042:2493355042(0) win 5840 (DF)
11:29:27.144844 10.0.1.189.35000 > 10.0.1.172.51123: S 2295506432:2295506432(0) ack 2493355043 win 8760
11:29:27.144852 10.0.1.172.51123 > 10.0.1.189.35000: . ack 1 win 5840 (DF)
11:29:27.144890 10.0.1.172.51123 > 10.0.1.189.35000: P 1:7(6) ack 1 win 5840 (DF)
11:29:27.144982 10.0.1.189.35000 > 10.0.1.172.51123: . ack 7 win 8754
11:29:27.145045 10.0.1.189.35000 > 10.0.1.172.51123: P 1:21(20) ack 7 win 8760
11:29:27.145062 10.0.1.172.51123 > 10.0.1.189.35000: . ack 21 win 5840 (DF)
11:29:27.145070 10.0.1.189.35000 > 10.0.1.172.51123: F 21:21(0) ack 7 win 8760
11:29:27.145093 10.0.1.172.51123 > 10.0.1.189.35000: F 7:7(0) ack 22 win 5840 (DF)
11:29:27.145175 10.0.1.189.35000 > 10.0.1.172.51123: . ack 8 win 8760
其中正常通讯时红色部分是主线程的发送命令,黑色是定时器发送的命令,这个TCP的通讯格式是对的.
异常通讯时:
11:29:28.090149 10.0.1.172.51136 > 10.0.1.189.35000: S 2488170508:2488170508(0) win 5840 (DF)
11:29:28.090426 10.0.1.189.35000 > 10.0.1.172.51136: S 2296850432:2296850432(0) ack 2488170509 win 8760
11:29:28.090436 10.0.1.172.51136 > 10.0.1.189.35000: . ack 1 win 5840 (DF)
11:29:28.090477 10.0.1.172.51136 > 10.0.1.189.35000: P 1:7(6) ack 1 win 5840 (DF)
11:29:28.090581 10.0.1.189.35000 > 10.0.1.172.51136: . ack 7 win 8754
11:29:28.090597 10.0.1.172.51136 > 10.0.1.189.35000: P 7:12(5) ack 1 win 5840 (DF)
11:29:28.090677 10.0.1.189.35000 > 10.0.1.172.51136: . ack 12 win 8755
11:29:28.100142 10.0.1.172.51137 > 10.0.1.189.35000: S 2494818819:2494818819(0) win 5840 (DF)
11:29:28.100700 10.0.1.189.35000 > 10.0.1.172.51136: P 1:12(11) ack 12 win 8760
11:29:28.100718 10.0.1.172.51136 > 10.0.1.189.35000: . ack 12 win 5840 (DF)
11:29:28.100766 10.0.1.189.35000 > 10.0.1.172.51136: F 12:12(0) ack 12 win 8760
11:29:28.100898 10.0.1.189.35000 > 10.0.1.172.51137: S 2296914432:2296914432(0) ack 2494818820 win 8760
11:29:28.100906 10.0.1.172.51137 > 10.0.1.189.35000: . ack 1 win 5840 (DF)
11:29:28.140127 10.0.1.172.51136 > 10.0.1.189.35000: . ack 13 win 5840 (DF)
11:29:29.100153 10.0.1.172.51138 > 10.0.1.189.35000: S 2496726679:2496726679(0) win 5840 (DF)
11:29:29.100429 10.0.1.189.35000 > 10.0.1.172.51138: S 2297618432:2297618432(0) ack 2496726680 win 8760
11:29:29.100440 10.0.1.172.51138 > 10.0.1.189.35000: . ack 1 win 5840 (DF)
11:29:29.100477 10.0.1.172.51138 > 10.0.1.189.35000: P 1:7(6) ack 1 win 5840 (DF)
11:29:29.100555 10.0.1.189.35000 > 10.0.1.172.51138: . ack 7 win 8754
11:29:29.100571 10.0.1.172.51138 > 10.0.1.189.35000: P 7:12(5) ack 1 win 5840 (DF)
11:29:29.100646 10.0.1.189.35000 > 10.0.1.172.51138: . ack 12 win 8749
11:29:33.100133 10.0.1.172.51137 > 10.0.1.189.35000: F 1:1(0) ack 1 win 5840 (DF)
11:29:33.100146 10.0.1.172.51138 > 10.0.1.189.35000: P 12:18(6) ack 1 win 5840 (DF)
11:29:33.102709 10.0.1.189.35000 > 10.0.1.172.51137: . ack 2 win 8760
11:29:33.102744 10.0.1.189.35000 > 10.0.1.172.51138: . ack 18 win 8743
11:29:33.102792 10.0.1.189.35000 > 10.0.1.172.51138: R 1:1(0) ack 18 win 8743
11:29:33.102845 10.0.1.189.35000 > 10.0.1.172.51137: F 1:1(0) ack 2 win 8760
11:29:33.102864 10.0.1.172.51137 > 10.0.1.189.35000: . ack 2 win 5840 (DF)
11:29:33.180144 10.0.1.172.51139 > 10.0.1.189.35000: S 2498729159:2498729159(0) win 5840 (DF)
11:29:34.100150 10.0.1.172.51140 > 10.0.1.189.35000: S 2501003931:2501003931(0) win 5840 (DF)
11:29:36.180132 10.0.1.172.51139 > 10.0.1.189.35000: S 2498729159:2498729159(0) win 5840 (DF)
...
...
以后Client(10.0.1.172)不停向Server(10.0.1.189)发送SYN.
|
你是怎么设置的定时器?信号?
|
看楼主这个服务器端程序真是长见识了。
竟然还可以这么写。。。
我还真保守啊,服务器端一直都只fork子进程来处理客户端,goto都基本不用。。。
竟然还可以这么写。。。
我还真保守啊,服务器端一直都只fork子进程来处理客户端,goto都基本不用。。。
|
试试
st_nonblocking(sockCmdListen);
sockCmdSvr = accept( sockCmdListen, (PSA)&addr, &size );
st_blocking(sockCmdListen);
...
st_nonblocking(sockCmdListen);
fdClose(sockCmdListen);
////////////////////////////////////////////////////
void st_nonblocking(int sid){
int flag;
flag = fcntl(sid,F_GETFL,0);
flag |= O_NONBLOCK;
fcntl(sid,F_SETFL,flag);
}
void st_blocking(int sid){
int flag;
flag = fcntl(sid,F_GETFL,0);
flag &= ~O_NONBLOCK;
fcntl(sid,F_SETFL,flag);
}
st_nonblocking(sockCmdListen);
sockCmdSvr = accept( sockCmdListen, (PSA)&addr, &size );
st_blocking(sockCmdListen);
...
st_nonblocking(sockCmdListen);
fdClose(sockCmdListen);
////////////////////////////////////////////////////
void st_nonblocking(int sid){
int flag;
flag = fcntl(sid,F_GETFL,0);
flag |= O_NONBLOCK;
fcntl(sid,F_SETFL,flag);
}
void st_blocking(int sid){
int flag;
flag = fcntl(sid,F_GETFL,0);
flag &= ~O_NONBLOCK;
fcntl(sid,F_SETFL,flag);
}
|
tcpdump -p 不让网络界面进入混杂模式
|
需要你用tcpdump的参数
说一下你在client的socket option吧.
ping不通是什么意思?能恢复吗?
netstat看listening port什么情况?
说一下你在client的socket option吧.
ping不通是什么意思?能恢复吗?
netstat看listening port什么情况?
|
都是很好的建议! 值得学习
|
接分先!