我有一个长度为20k的字符串需要发送,调用一次send()发送不成功,是不是必须循环调用?还有,循环调用的话接收端循环recv()后,是不是有可能后send()的数据先到,我是不是还要自己组织recv()后的数据?谁有这方面的详细代码。

解决方案 »

  1.   

    使用非阻塞socket
    另外,tcp是保证次序的
      

  2.   

    You can send the data(20K) directly and no need to concern the data order that TCP had done itThe only thing you must concern is to deal the recv data on the recv endpoint
      

  3.   

    我又试了一下,问题出在字符串的大小上,我用的是win32汇编,编程环境是masm,定义临时变量时,为什么local buffer[4096]:byte运行正常,而local buffer[5000]:byte就不正常了 ,我还以为是send的问题。还有如果有一个大文件,循环send的话,到接收端是不是要自己组织recv来的数据?比如用了5次send,即使tcp是保证次序的,但能保证5次send按发送的顺序recv到么?会不会第4次send的部分先于第3次send的部分被recv到?
      

  4.   

    1 栈空间的大小是有限制的,与操作系统以及编译器都有关系
    2 如果是阻塞方式的,你按12345的顺序send,那么recv的时候,也是严格按照12345接收的,不会出现顺序错误
      

  5.   

    The data was copied to kernel buffer sequence when you call send functionThe default max stack size is about 1M in apand What`s the size in masm?you should check it