Skip to content

Adapter unable to connect to multiple clients. #8

@adityarauniyar

Description

@adityarauniyar

The steps:

  1. Adapter is running successfully and gathering data.
  2. Agent connects to the adapter and collects data as expected.
  3. A telnet to the adapter port rejects any connection.
  4. The telnet connects as soon as the agent is stopped.

I think that the additional clients are in a queue till the connected client thread is terminated. Ref

Have tried to test the following code and seems to work. Please review.

private void HeartbeatClient(object client)
        {
            ...
            // Send intial stream to the client
            SendAllTo(clientStream);
            ...
            try
            {
                while (mRunning && tcpClient.Connected)
                {
                   ...
                }
            }
        }

        private void ListenForClients()
        {
            mRunning = true;

            try
            {
                while (mRunning)
                {
                    //create a thread to handle a new communication
                    Thread clientThread = new Thread(new ParameterizedThreadStart(HeartbeatClient));
                    //.AcceptTcpClient() blocks until a client has connected to the adapter
                    // a connection attaches the new client to the new thread
                    clientThread.Start(mListener.AcceptTcpClient());          

                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Execption occurred waiting for connection: " + e.Message);
            }

            finally
            {
                mRunning = false;
                mListener.Stop();
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions