在做一个聊天小程序,有客户端和服务器端,要求使用多线程的,请问一下,多线程要用在什么地方比较适当,能大大提高效率?还有,就是看了WSASend()之类的2.0的新函数,其中很多是有一个参数,像WSASend()的第二个参数,允许有多个buffer指针,不过我看不大懂如何用,一个参数如何使用多个buffer指针?

解决方案 »

  1.   

    WSABUF DataBuf;
    char SendBuf[1024] = "Test data to send.";
    int BufLen = 1024;...DataBuf.len = BufLen;
    DataBuf.buf = SendBuf;...WSASend(SendSocket, 
      &DataBuf, 
      1,
      &BytesSent,
      Flags,
      (SOCKADDR*) &RecvAddr,
      RecvAddrSize,
      &Overlapped,
      NULL);
      

  2.   

    第2个参数实际是一个结构体.
    MSDN的描述如下:
    lpBuffers 
    [in] Pointer to an array of WSABUF structures. Each WSABUF structure contains a pointer to a buffer and the length of the buffer, in bytes. This array must remain valid for the duration of the send operation.此处的Each不是指的允许有多个buffer指针. 
      

  3.   

    非常感谢!!基本明白了。还有一点小问题就是在服务器端,是不是要为第一个连接在它上面的SOCKET创建一个线程?还有有别的方法?我是想A发信息到B的话,是需要通过服务器转发的