In VB.net socket client program, the client keeps disconnecting on Windows 7
I have a <acronym title="Visual Basic">VB</acronym>.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. I have migrated the program from Visual Studio 2005 to Visual Studio 2010 and it still has the same problem. Is there something on Windows 7 that is disconnecting my socket connection? 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
March 21st, 2012 4:22pm

I found the problem. My Socket server was sending packets with the URG flag set. Windows 7 did not like the way this was being done, I guess.
Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2012 5:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics