gpt4 book ai didi

vb.net - VB.NET 3.5 SocketException在部署但不在开发机器上

转载 作者:行者123 更新时间:2023-12-03 11:50:55 25 4
gpt4 key购买 nike

我已经编写了一个异步UDP客户端来与我公司的服务器通信。当我在开发人员计算机上运行时,一切都很好。当我部署到另一台计算机时,我第一次通过套接字发送数据时,在EndReceive上收到套接字异常。我的开发箱是Win7,我已经部署到XP SP3机器和Server 2003 R2机器上。下面是接收代码:

Private Sub ReceiveCallback(ByVal ar As IAsyncResult)
Try
' Retrieve the state object and the client socket
from the asynchronous state object.'

Dim state As StateObj = CType(ar.AsyncState, StateObj)
Dim client As Socket = state.sockArg

' Read data from the remote device.'
Dim bytesRead As Integer
receiveDone.WaitOne(Timeout.Infinite)

bytesRead = client.EndReceive(ar)
If bytesRead > 0 Then
Dim s As String = Encoding.ASCII.GetString(state.buffer, 0, bytesRead)
parsedata(s)
End If
Catch SockEx As SocketException
mlog.Error(String.Format("ID={1} {0} SocketError={2}", SockEx.Message, ID.ToString, SockEx.SocketErrorCode.ToString), SockEx)
Catch ox As System.ObjectDisposedException
mlog.Warn(String.Format("Object Disposed ID={0}", ID.ToString))
Catch ex As Exception
mlog.Error(String.Format("{1} ID={0}", ID.ToString, ex.Message), ex)
End Try
End Sub 'ReceiveCallback

我得到的异常(exception)是:

System.Net.Sockets.SocketException:由于线程退出或应用程序请求,I/O操作已中止
在System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
在RTSPc.Connection.ReceiveCallback(IAsyncResult ar)

SocketException是OperationAborted

最佳答案

它可能不会在您的开发箱上失败的原因是,在Vista中更改了I/O系统的基本行为,以便在线程退出时不再取消由线程发出的重叠I/O。 。

请参阅我的博客上有关此内容的帖子:http://www.lenholgate.com/blog/2008/02/major-vista-overlapped-io-change.html

现在,为什么要在XP上遇到问题才是真正的问题,要回答这个问题,我们可能需要更多地了解您如何发出重叠的I/O请求以及从何处发出。您是否在运行自己的线程?他们是否发出任何I/O请求?

关于vb.net - VB.NET 3.5 SocketException在部署但不在开发机器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1609706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com