Git Product home page Git Product logo

Comments (9)

ibekaddour avatar ibekaddour commented on July 22, 2024

Hello,
Could you please provide more details about the issue, also how you are running the client and server.
Thank you.

from lib60870.net.

iman7107 avatar iman7107 commented on July 22, 2024

Hi again.
I use Axon Test software as RTU(Server) IEC104 simulator.
This is my Connect method body:

 con = new Connection(IPTextBox.Text, Convert.ToInt32(PortTextBox.Text));
            con.DebugOutput = true;
            con.SetASDUReceivedHandler(asduReceivedHandler, null);
            con.SetConnectionHandler(ConnectionHandler, null);
            try
            {
                con.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

and I do something in ASDURecieveHandler.
everything is OK. But when I click on Disconnect Button my form run ino Hang.
This is my Disconnect method body:

     try
                {
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Close Connection Error : " + Environment.NewLine + ex.ToString(), "Close Connection Error");
                }


I changed my code and now my Disconnect method body is like this:

     try
                {
                    con.Cancel();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Close Connection Error : " + Environment.NewLine + ex.ToString(), "Close Connection Error");
                }

and now it is OK. Should I call con.Cancel() before con.Close() ? I saw Cancel method close the Socket and because of this, I called Cancel() method before Close(). Did I do correct way?

from lib60870.net.

juwiefer-btc avatar juwiefer-btc commented on July 22, 2024

Your call to Close() is not within the ASDURecieveHandler, right? I guess that would cause a deadlock. But calling Cancel() should not help in that case.
I don't think that you are supposed to call Cancel() before Close(), but that might still be a viable workaround.

I'm not sure if the way "running = false" is set in one thread to signal another thread to stop is correct without any synchronization.

from lib60870.net.

iman7107 avatar iman7107 commented on July 22, 2024

Yes. That's right. I call Close() Method in button_Click event, not in ASDURecieverHandler.
So, how can I Close the connection in IEC104 Client? I sometimes need to disconnect my client.
What solution do you suggest?

from lib60870.net.

ibekaddour avatar ibekaddour commented on July 22, 2024

First you need to ensure that the connection object is not null before attempting to close it.
if (con != null)

What you can try then is calling the Disconnect() method, or maybe after calling Close() or Disconnect() you can call Dispose() this dispose of the connection object after closing it.

from lib60870.net.

iman7107 avatar iman7107 commented on July 22, 2024

Disconnect()? I can't find Disconnect method.
I can call Dispose() as long as Close() method completes. But the problem is that it does not come out of Close() method.

from lib60870.net.

ibekaddour avatar ibekaddour commented on July 22, 2024

Since the issue is coming from workerThread.Join(); You can put a condition that will wait for the worker thread to finish within a specified timeout. If the thread does not finish within the timeout, it will close the connection.

from lib60870.net.

mzillgith avatar mzillgith commented on July 22, 2024

Could it be that the connection thread is stuck in the connection handler? When you are calling the UI in the connection handler then it could be a deadlock because the workerThread.Join is also running in the UI thread.

from lib60870.net.

iman7107 avatar iman7107 commented on July 22, 2024

Hi.
I changed my code and moved my connect and disconnect method into another thread (Background worker) and my problem solved.
Thanks a lot.

from lib60870.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.