CS下面的SOcket问题
我超级郁闷的,别人用TCP经常会粘包,我的TCP不会粘包,反而会断包!!
是这样的,最近在做一个项目,需要用到socket发送文件,我在每次发送的时候定义了发送的包的总个数,包当前ID,最后包的大小,可是在发送的过程中,经常出现了发送失败,结果我对发送缓冲区的数据,和接收缓冲区的数据打印出来,发现,发送方的数据正常,但是接收方却把一个发送包拆成了两次接收,就变成了下面这样
发送方数据:
185,88,141,134,95,212,80,26,167,6,29,34,21,243,100,7,63,250,100,65,194,102,162,63,222,255,224,214,173,222,179,92,121,103,115,169,248,136,164,108,115,224,225,231,224,190,124,70,70,212,143,144,81,132,225,133,146,121,101,218,149,71,202,174,84,
接收方第一个包的数据:
185,88,141,134,95,212,80,26,167,6,29,34,21,243,100,7,63,250,100,65,194,102,162,63,222,255,224,214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
接收方第二个包的数据:
173,222,179,92,121,103,115,169,248,136,164,108,115,224,225,231,224,190,124,70,70,212,143,144,81,132,225,133,146,121,101,218,149,71,202,174,84
可是我明明每个接收方的缓冲区都设定了大小,为什么会出现以上这种情况??
谁懂的麻烦告诉我一下
------解决方案--------------------
------解决方案--------------------意味着一次receive最多1020个字节 --> 意味着一次receive最多10240个字节
难道你认为生命多大的buffer,那么.net就得填满了?
------解决方案--------------------mark,暂时还没发现声明了较大缓冲区但是.net一次只填一部分的问题,坐等答案。
------解决方案--------------------
------解决方案--------------------哦,又查了一下,不管发送方是怎么发的,接收方的缓存是怎么定义的,TCP每次接收到的数据量都是不固定的,谢谢~