tsgdavid
New member
I have a VB.Net socket client application using the Receive method in a background thread. This has been working great for some time and it is still working great. I am now trying to run this client on Windows 7 instead of Windows XP Pro. What works great on XP does not work well on Windows 7. My receive method reliably gets an exception on the 9th message received. The exception is "An established connection was aborted by the software in your host machine". Everything works correctly except that the socket connection keeps disconnecting.
Can anyone help me figure out how to prevent this connection from disconnecting? I can send all the messages that I want with no problems. I am tracing the packets on the network and it appears that the Windows 7 client is the host that is resetting the connection. The receive data looks good.
Here are some excerpts from my code to give you an idea what I am doing:
PrivateSub SocketConnect()
Dim RecvThread AsNewThread(AddressOf ReceiveMsg)
tmrConnect.Enabled =False
ClientSocket =NewSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 0)
Try
ClientSocket.Connect(HostName, PortNum)
ConnectedUI()
SocketRefresh()
RecvThread.IsBackground =True
RecvThread.Start()
Catch ex AsException
DisconnectedUI()
EndTry
EndSub
PrivateSub ReceiveMsg()
Try
nNumBytes = -1
While (nNumBytes <> 0)
nTotalBytes = 0
RecvBuffer.Initialize()
nNumBytes = 0
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, 4, SocketFlags.None)
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
nMsgType = BitConverter.ToInt16(RecvBuffer, 0)
nMsgLen = BitConverter.ToInt16(RecvBuffer, 2)
While (nTotalBytes < nMsgLen And nNumBytes > 0)
nNumBytes = 0
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, (nMsgLen - nTotalBytes), _
SocketFlags.None)
' !!!!!! EXCEPTION occurs here !!!!!!!
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
EndWhile
AppendText("Total Bytes Received = " & Str(nTotalBytes))
AppendText("MsgLen expected = " & Str(nMsgLen))
SelectCase nMsgType
Can anyone help me figure out how to prevent this connection from disconnecting? I can send all the messages that I want with no problems. I am tracing the packets on the network and it appears that the Windows 7 client is the host that is resetting the connection. The receive data looks good.
Here are some excerpts from my code to give you an idea what I am doing:
PrivateSub SocketConnect()
Dim RecvThread AsNewThread(AddressOf ReceiveMsg)
tmrConnect.Enabled =False
ClientSocket =NewSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 0)
Try
ClientSocket.Connect(HostName, PortNum)
ConnectedUI()
SocketRefresh()
RecvThread.IsBackground =True
RecvThread.Start()
Catch ex AsException
DisconnectedUI()
EndTry
EndSub
PrivateSub ReceiveMsg()
Try
nNumBytes = -1
While (nNumBytes <> 0)
nTotalBytes = 0
RecvBuffer.Initialize()
nNumBytes = 0
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, 4, SocketFlags.None)
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
nMsgType = BitConverter.ToInt16(RecvBuffer, 0)
nMsgLen = BitConverter.ToInt16(RecvBuffer, 2)
While (nTotalBytes < nMsgLen And nNumBytes > 0)
nNumBytes = 0
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, (nMsgLen - nTotalBytes), _
SocketFlags.None)
' !!!!!! EXCEPTION occurs here !!!!!!!
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
EndWhile
AppendText("Total Bytes Received = " & Str(nTotalBytes))
AppendText("MsgLen expected = " & Str(nMsgLen))
SelectCase nMsgType