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. Why Does GXNet Socket Attribute Become Null After Starting a Thread?

Why does GXNet socket attribute become null after starting a thread?

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 SgmUsr , 23 December, 2019
Forums
Gurux.Net

Hi,

I'm following the Gurux.DLMS.Meter.Listener.Net example but when I try to start thread with my personal class method DeviceManager.StartManageDevice() (class builds like GXDLMSReader, with same attribute), the private attribute "socket" of GXNet object becomes null and I can't send and receive data.

private void GXNetSocket_OnReceived(object sender, Gurux.Common.ReceiveEventArgs e)
{
GXNet server = (GXNet)sender;
try
{
using (GXNet cs = server.Attach(e.SenderInfo))
{
...
DeviceManager dm = new DeviceManager(cs, matricola, sst, frameCounter);
Thread currentThread = new Thread(dm.StartManageDevice);
currentThread.Start();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

I don't understand why.

Thanks

Profile picture for user Kurumi

Kurumi

6 years 5 months ago

Hi,

Hi,

The reason for this is because you attach the GXNew client and it's released after you leave OnReceived.

Try to attach the net media in your thread.

BR,
Mikko

SgmUsr

6 years 5 months ago

In reply to Hi, by Kurumi

Hi Mikko,

Hi Mikko,

now it works.

Thanks

SgmUsr

6 years 5 months ago

In reply to Hi, by Kurumi

Hi Mikko,

Hi Mikko,

about this question, this works correctly with Tcp, but with Udp connections I can't use Attach() method: I only need to pass GXNet object in a thread?

Thanks

Profile picture for user Kurumi

Kurumi

6 years 5 months ago

In reply to Hi Mikko, by SgmUsr

Hi,

Hi,

In UDP there are no connections. If you know the sender address and port you can send data directly.

BR,
Mikko

SgmUsr

6 years 5 months ago

In reply to Hi, by Kurumi

hi,

hi,

but how is it possible GXNet.Send has its attribute 'socket' (being socket a IDisposable type) as UdpClient type? because, if I call back Send method (from GXNet), I'm using GXNet object, not UdpClient object, so the attribute socket will be null.

I cannot understand this thing.

Thanks

  • 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