结束挂起的异步发送。[C#]
public int EndSend(
IAsyncResult asyncResult
);参数
asyncResult
IAsyncResult,它存储此异步操作的状态信息。
返回值
如果成功,则将返回向 Socket 发送的字节数;否则会返回无效 Socket 错误。你应该看看返回的是不是发送成功?
public int EndSend(
IAsyncResult asyncResult
);参数
asyncResult
IAsyncResult,它存储此异步操作的状态信息。
返回值
如果成功,则将返回向 Socket 发送的字节数;否则会返回无效 Socket 错误。你应该看看返回的是不是发送成功?
我已经发送了9次啊,而且在局域网内没有任何问题。我在本市网吧也试过了没有问题,只是外地的朋友通讯不上,不知道为什么了。
private delegate void SetValue(string con);
private void callbackOnServer1Send(IAsyncResult asResult)
{
int bytesCount = this.Server1.EndSend(asResult);
if(textBox.InvokeRequired)
{
textBox1.AppendText("发送成功"+Environment.NewLine);}
在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);
}
把做法写出来,大家帮我看看还有没有更好的方法
private byte[] buf[] = new byte[1024];
...
...
...
this.ClientCon.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, this.buf.Length);
只加了这一句,把Socket发送缓冲区的大小和我使用的缓冲区的大小设的一样就好了
主要原因是对方网络不好,造成我这里发送超时
是放在哪个位置
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());
}
}