GXNet.Open() causes randomly SocketExceptions

4 posts / 0 new
Last post
Stier
Stier's picture
GXNet.Open() causes randomly SocketExceptions

Hey Mikko

I actually dealing with a random problem with the GXNet.Open() Method. Inside Open the method ClientConnect is called. The connect attempt is limited to TIMEOUT_MILLISECONDS which is constant 5 seconds. After this 5 seconds (independently if the connect succeeds) there is a call to Socket.BeginReceive.
First, whats the purpose of this BeginReceive?
I get random SocketException when I try to connect meters via GSM/GPRS. Depends on how long the meter needs to connect and this varies a lot over the air. As I interpret the Exception, the problem occurs, if the 5 second timeout exceeds. After this 5 seconds the BeginReceive tries to execute, but the socket is not connected, which causes the following Exception:

System.Net.Sockets.SocketException (0x80004005): A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
at Gurux.Net.GXNet.ClientConnect(EndPoint ep) at Gurux.Net.GXNet.Open() at NP.Metering.Unit.Adapter.Dlms.GXDLMSCommunicator.Open()

I'm not sure if I interpret this problem correctly. Any suggestions from your side?
Thanks a lot for your help!

Best regards,
Andrea

Stier
Stier's picture
Further investigation in the GXNet.Open() problem

Hey Mikko,

I did some more investigation in the GXNet.Open() problem. I took the source of GXNet, replaced the constant TIMEOUT_MILLISECONDS with an exposed porperty within the GXNet.cs and increased the timeout in my application to 30 seconds. Since there the SocketException does not occur anymore within the Open method. Seems to be a solution to my problem, but I 'm still wondering about the BeginReceive after the connect?

Best regards,
Andrea

kurumi
kurumi's picture
Further investigation in the GXNet.Open() problem

Hi Andrea,

I see your problem. We'll add this wait time to media component so you can increase it if needed.
We release new version tomorrow.

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org

Stier
Stier's picture
Further investigation in the GXNet.Open() problem

Hi Mikko,

Thanks a lot for your effort, that will help a lot!
I'm still curious about the BeginReceive after connect? Whats the purpose of this receive? Does the meter send some data after connect?

Best regards,
Andrea