注意:在Unix系统下,如果recv函数在等待协议接收数据时网络断开了,那么调用recv的进程会接收到一个SIGPIPE信号,进程对该信号的默认处理是进程终止 。
1 #include "socketclient.h" 2 int main() 3 { 4 SocketClient cli; 5 char* szIp = "127.0.0.1"; 6 WORD wPort = 5082; 7 int nRet = cli.Open(szIp,wPort); 8 if (nRet!=0) 9 {10 printf("Open %s:%d error:%d rn",szIp,wPort,nRet);11 return -1;12 }13 char buf[1600];14 int i=1;15 DWORD dwTickCount0 = 0;16 DWORD dwTickCount1 = 0;17 int nSended = 0;18 while (1)19 {20 dwTickCount0 = cli.GetTickCount();21 //printf("%d,TickCount(0):%u rn",i,dwTickCount0);22 23 nSended = cli.Send(buf,1500); //超时2秒发送24 25 dwTickCount1 = cli.GetTickCount();26 //printf("%d,TickCount(1):%u rn",i,dwTickCount1);27 //usleep(20*100);28 printf("%d,time:%u,sended:%d,err:%d rn",i,dwTickCount1 - dwTickCount0,nSended,errno);29 if (nSended<1)30 {31 break;32 }33 i++;34 }35 }1,time:0,sended:1500,err:0 2,time:0,sended:1500,err:0 3,time:0,sended:1500,err:0 4,time:0,sended:1500,err:0 5,time:0,sended:1500,err:0 6,time:0,sended:1500,err:0 7,time:0,sended:1500,err:0 8,time:1,sended:1500,err:0 9,time:0,sended:1500,err:0 10,time:0,sended:1500,err:0 11,time:0,sended:1500,err:0 12,time:0,sended:1500,err:0 13,time:0,sended:1500,err:0 14,time:0,sended:1500,err:0 15,time:0,sended:1500,err:0 16,time:0,sended:1500,err:0 17,time:0,sended:1500,err:0 18,time:0,sended:1500,err:0 19,time:0,sended:1500,err:0 20,time:0,sended:1500,err:0 21,time:0,sended:1500,err:0 22,time:0,sended:1500,err:0 23,time:0,sended:1500,err:0 24,time:0,sended:1500,err:0 25,time:0,sended:1500,err:0 26,time:0,sended:1500,err:0 27,time:0,sended:1500,err:0 28,time:0,sended:1500,err:0 29,time:0,sended:1500,err:0 30,time:0,sended:1500,err:0 31,time:0,sended:1500,err:0 32,time:0,sended:1500,err:0 33,time:0,sended:1500,err:0 34,time:0,sended:1500,err:0 35,time:0,sended:1500,err:0 36,time:0,sended:1500,err:0 37,time:0,sended:1500,err:0 38,time:0,sended:1500,err:0 39,time:0,sended:1500,err:0 40,time:0,sended:1500,err:0 41,time:0,sended:1500,err:0 42,time:0,sended:1500,err:0 43,time:0,sended:1500,err:0 44,time:0,sended:1500,err:0 45,time:0,sended:1500,err:0 46,time:0,sended:1500,err:0 47,time:0,sended:1500,err:0 48,time:39,sended:1500,err:0 49,time:0,sended:1500,err:0 50,time:0,sended:1500,err:0 51,time:0,sended:1500,err:0 52,time:0,sended:1500,err:0 53,time:0,sended:1500,err:0 54,time:0,sended:1500,err:0 55,time:0,sended:1500,err:0 56,time:0,sended:1500,err:0 57,time:0,sended:1500,err:0 58,time:0,sended:1500,err:0 59,time:0,sended:1500,err:0 60,time:0,sended:1500,err:0 61,time:0,sended:1500,err:0 62,time:0,sended:1500,err:0 63,time:0,sended:1500,err:0 64,time:0,sended:1500,err:0 65,time:0,sended:1500,err:0 66,time:0,sended:1500,err:0 67,time:0,sended:1500,err:0 68,time:0,sended:1500,err:0 69,time:0,sended:1500,err:0 70,time:0,sended:1500,err:0 71,time:0,sended:1500,err:0 72,time:0,sended:1500,err:0 73,time:0,sended:1500,err:0 74,time:0,sended:1500,err:0 75,time:0,sended:1500,err:0 76,time:0,sended:1500,err:0 77,time:0,sended:1500,err:0 78,time:0,sended:1500,err:0 79,time:0,sended:1500,err:0 80,time:0,sended:1500,err:0 81,time:0,sended:1500,err:0 82,time:0,sended:1500,err:0 83,time:0,sended:1500,err:0 84,time:0,sended:1500,err:0 85,time:0,sended:1500,err:0 86,time:0,sended:1500,err:0 87,time:0,sended:1500,err:0 88,time:0,sended:1500,err:0 89,time:0,sended:1500,err:0 90,time:0,sended:1500,err:0 91,time:0,sended:1500,err:0 92,time:0,sended:1500,err:0 93,time:0,sended:1500,err:0 94,time:0,sended:1500,err:0 95,time:0,sended:1500,err:0 96,time:0,sended:1500,err:0 97,time:0,sended:1500,err:0 98,time:0,sended:1500,err:0 99,time:0,sended:1500,err:0 100,time:0,sended:1500,err:0 101,time:0,sended:1500,err:0 102,time:0,sended:1500,err:0 103,time:0,sended:1500,err:0 104,time:0,sended:1500,err:0 105,time:0,sended:1500,err:0 106,time:0,sended:1500,err:0 107,time:0,sended:1500,err:0 108,time:0,sended:1500,err:0 109,time:0,sended:1500,err:0 110,time:0,sended:1500,err:0 111,time:0,sended:1500,err:0 112,time:0,sended:1500,err:0 113,time:0,sended:1500,err:0 114,time:0,sended:1500,err:0 115,time:0,sended:1500,err:0 116,time:0,sended:1500,err:0 117,time:0,sended:1500,err:0 118,time:0,sended:1500,err:0 119,time:0,sended:1500,err:0 120,time:0,sended:1500,err:0 121,time:0,sended:1500,err:0 122,time:0,sended:1500,err:0 123,time:0,sended:1500,err:0 124,time:0,sended:1500,err:0 125,time:1999,sended:340,err:0 //这里出现了发送不全126,time:0,sended:1500,err:0 127,time:0,sended:1500,err:0 128,time:0,sended:1500,err:0 129,time:0,sended:1500,err:0 130,time:0,sended:1500,err:0 131,time:0,sended:1500,err:0 132,time:0,sended:1500,err:0 133,time:0,sended:1500,err:0 134,time:0,sended:1500,err:0 135,time:0,sended:1500,err:0 136,time:0,sended:1500,err:0 137,time:0,sended:1500,err:0 138,time:0,sended:1500,err:0 139,time:0,sended:1500,err:0 140,time:0,sended:1500,err:0 141,time:0,sended:1500,err:0 142,time:0,sended:1500,err:0 143,time:0,sended:1500,err:0 144,time:0,sended:1500,err:0 145,time:0,sended:1500,err:0 146,time:0,sended:1500,err:0 147,time:2000,sended:1268,err:0 148,time:2000,sended:-1,err:11同样send也会出现和recv一样,会有发送不全的现象.
以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!
「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助:- 拍照手机大行其道的时代
- 迈凯轮已经悄悄将其Elva超级跑车的生产量减少
- 鸿星尔克快倒闭?其实它是行业第二大品牌,价值超过李宁、361°
- 拼多多流量怎么挽救 拼多多流量下降是什么原因
- 医生建议上午拔牙的原因有哪些
- 苹果手机电池不耐用 苹果手机电池不耐用,手机发热是什么原因
- 小米电动牙刷自启动引争议 小米电动牙刷自己突然启动是什么原因
- 肾结石出现的六大原因 预防肾结石复发的饮食调理
- 狗喝水老呛是什么原因,狗狗呛到咋办?
- 男人有钱就变坏是什么原因?