Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. GXNet.Open() Causes Randomly SocketExceptions

GXNet.Open() causes randomly SocketExceptions

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By Stier , 7 November, 2017
Forums
Gurux.Net

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

8 years 7 months ago

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

Profile picture for user Kurumi

Kurumi

8 years 7 months ago

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

Stier

8 years 7 months ago

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

Profile picture for user Kurumi

Kurumi

8 years 6 months ago

Further investigation in the GXNet.Open() problem

Hi,

BeginReceive start listens received messages. Some meter might send data right away.

BR,

Mikko

Stier

8 years 6 months ago

Further investigation in the GXNet.Open() problem

Hi Mikko

Funny concept to send data right after the connect, but I already experienced a lot of funny (or annoying) features with "smart" meters! :D
But anyway, thanks for your info!

Best regards,
Andrea

Profile picture for user Kurumi

Kurumi

8 years 5 months ago

Further investigation in the GXNet.Open() problem

Hi,

Some protocols are using so-called readout-mode. It means that meters are quite simple and they just report current values after the connection is made. You can't ask anything from the meter.

BR,

Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin