Click here to Skip to main content
15,943,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
after sending a TCP packet to a slave board, I need to wait indefinitely for an answer. I am using Windows 10 Pro, Visual Studio 2022 and I am using a VB project with the function below (Running on a different thread then the main program)

The parameter gSocket.ReceiveTimeout = -1 does not have any influence on the exception time. If the board answers in less than 12 seconds, all runs well. It if takes more than 12 seconds, a Socket timeout exception is thrown, independent of the gSocket.ReceiveTimeout value. Even when it is set to 0 or -1 ...(Infinite time). Any suggestions ? Thanks !!!

Dim gSocket As Socket
gSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

gSocket.ExclusiveAddressUse = True
gSocket.LingerState = New LingerOption(True, 10)
gSocket.NoDelay = True



gSocket.SendTimeout = -1

'Receive response.
Dim vBuffer(20) As Byte
For i = 0 To 19
vBuffer(i) = 0
Dim vNumOfBytesReceived As Integer = 0
gSocket.ReceiveTimeout = -1
vNumOfBytesReceived = gSocket.Receive(vBuffer, 0, 20, SocketFlags.None)


Catch ex As Exception
End Try

What I have tried:

I have tried all solutions I know, but I have never been able to extend the timeout of the receive TCP packet command. I need it to keep waiting for al least 3 minutes. But after 12 seconds it always throws an exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900