Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi guys! This is a pretty tough question, I think. Sorry that its pretty long, too.

I have a problem with communicating with a lab apparatus. For the interface to work, I have to send back acknowledgements. That seems to be the problem, because the apparatus only sends the first message, after I send back the acknowledgement, it doesn't respond anymore.
Here is the code
C#
private void listener()       {
       try    {
            // ... variables and stuff...

            // Enter the listening loop.
            while (!done)  {
                // Perform a blocking call to accept requests.
                TcpClient client = tcpListener.AcceptTcpClient();

                // Get a stream object for reading and writing
                stream = client.GetStream();
                lanReader = new BinaryReader(stream);
                lanWriter = new BinaryWriter(stream);

                conversation = true; //will be set to false again after END
                string cache = "";
                // ... (this part works)
                processReceivedData();
                // ...
           }
     }
}
// after receiving data in a loop above, it's being processed by the following function:

private void processReceivedData()       {
     if (daten.Contains("<HEL.") && daten.Contains("</HEL")) { // Hello Message received
          sendACK();
     }
     // ... (status, other messages, measurements...)
}


private bool sendACK()    {
    if (lanWriter.BaseStream == null) //lanWriter initialized in the beginning
         return false;
    lanWriter.Write(ACK); //ACK: Acknowledgement message string
    return true;
}


So basically, after the apparatus starts communication, the reading and writing streams are opened, but simply writing in it doesn't seem to work. What am I doing wrong?
Do I have to set the IP of the apparatus somewhere (I can access that)?
Posted
Updated 20-Nov-13 11:59am
v3
Comments
Garth J Lancaster 20-Nov-13 18:32pm    
it would help if you indicated what the 'apparatus' was, in case someone else has experience with it (and may know how to do diagnostics on it)

Without this info, I doubt someone could say wether its your 'blocking client' or your setup 'tcp/ip address' or what, not knowing what the beast actually is


I'd be looking at wether the lanWriter.Write(ACK) message actually gets back to the apparatus ....
The Manoj Kumar 20-Nov-13 23:57pm    
How about using NetworkStream in place of Stream. Here is a example http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.getstream%28v=vs.110%29.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900