结束挂起的异步发送。[C#]
public int EndSend(
   IAsyncResult asyncResult
);参数
asyncResult 
IAsyncResult,它存储此异步操作的状态信息。 
返回值
如果成功,则将返回向 Socket 发送的字节数;否则会返回无效 Socket 错误。你应该看看返回的是不是发送成功?

解决方案 »

  1.   

    用什么连的?在网络不是很好的情况下(尤其是异地发送),使用tcp连比udp好。
      

  2.   

    我用的就是tcp
    我已经发送了9次啊,而且在局域网内没有任何问题。我在本市网吧也试过了没有问题,只是外地的朋友通讯不上,不知道为什么了。
      

  3.   

    在callbackOnServer1Send()的方法中用一下委托和ui传消息
    private delegate void SetValue(string con);
    private void callbackOnServer1Send(IAsyncResult asResult)
    {
        int bytesCount = this.Server1.EndSend(asResult);
        if(textBox.InvokeRequired)
        {
        textBox1.AppendText("发送成功"+Environment.NewLine);}
      

  4.   

    [over write]
    在callbackOnServer1Send()的方法中用一下委托和ui传消息private delegate void SetValue();
    private void callbackOnServer1Send(IAsyncResult asResult)
    {
        int bytesCount = this.Server1.EndSend(asResult);
        if(textBox.InvokeRequired)
        {
          this.Invoke(new SetValue(SetValueToText),null);
        }
    }
    priavte void SetValueToText()
    {
        textBox1.AppendText("发送成功"+Environment.NewLine);
    }
      

  5.   

    谢谢各位了,问题基本解决了
    把做法写出来,大家帮我看看还有没有更好的方法
    private byte[] buf[] = new byte[1024];
    ...
    ...
    ...
    this.ClientCon.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, this.buf.Length);
    只加了这一句,把Socket发送缓冲区的大小和我使用的缓冲区的大小设的一样就好了
    主要原因是对方网络不好,造成我这里发送超时
      

  6.   

    this.ClientCon.SetSocketOption(SocketOptionLevel.Socket,   SocketOptionName.SendBuffer,   this.buf.Length); 
    是放在哪个位置
      

  7.   

    我碰到的也是这个问题,客户端发送给服务器转发的程序,发送一会,服务器就收不到了,但调试发现确实还在发送,而且socket的TCP也没有断!用你的方法试试
      

  8.   

    因为我每次发送的数据的大小不一样,所以我是在发送之前设置一下
     private void videoBufferSend(Socket handler, byte[] byteData)
            {
                try
                {
                    
                    handler.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, byteData.Length); 
                    // Begin sending the data to the remote device.
                    handler.BeginSend(byteData, 0, byteData.Length, 0,
                        new AsyncCallback(videoBufferSendCallback), handler);
                }
                catch (Exception e)
                {
                    MessagerichTextBox.Invoke(MessageTextBoxdel,e.ToString());
                }
            }
      

  9.   

    我在想,楼主是不是碰到了NAT问题