more G-Labs products

Author Topic: How to using in TCPclient on the received option  (Read 933 times)

January 29, 2015, 01:24:11 PM
Read 933 times

kobi.beja

  • *
  • Information
  • Newbie
  • Posts: 21
Hi
I'm using this code to send command via tcp to some device on the network,
The device sending feedback and I want to use it.
I'm not really know how to "capture the command" and using the feedback to something else.
how it's possible?

The command that came from the device is ">FN,OUT,OFF,2"

Code: [Select]
var remoteserver = "192.168.1.147";
 
Action<string>
HandleStringReceived = (string message) => {
 
  // this will be called every time a message is received from the remote endpoint
Program.Notify("TcpClient String", message);
 
};

Action<byte[]>
HandleMessageReceived = (byte[] message) => {
 
  // this will be called every time a message is received from the remote endpoint
Program.Notify("TcpClient Bytes", BitConverter.ToString(message));
 
};

Action<bool>
HandleStatusChanged = (bool connected) => {
 
  // this will be called every time the connection status changes
  Program.Notify("TcpClient Status", connected ? "CONNECTED!" : "DISCONNECTED!");
 
};

// open the serial port channel and register handlers
TcpClient
  .Service( remoteserver ) // server
  .OnStatusChanged( HandleStatusChanged )
  .OnMessageReceived( HandleMessageReceived )
  .OnStringReceived( HandleStringReceived )
  .Connect( 7078 ); // port

// this is the main program loop
while (Program.IsEnabled)
{
if (TcpClient.OnMessageReceived(">FN,OUT,OFF,2")
{
     TcpClient.SendMessage("FN,TOG,1\x0D");
}
    Pause(3);
    TcpClient.Disconnect();
    Pause(3);
    //
    break;
}

January 29, 2015, 08:44:45 PM
Reply #1

kobi.beja

  • *
  • Information
  • Newbie
  • Posts: 21
Hi
I'm  :'(trying to understand but without any success. :'(

Code: [Select]
     if (TcpClient.OnStringReceived((message)">FN,OUT,OFF,2")
{
     TcpClient.SendMessage("bla bla bal");
}
    Pause(3);
    TcpClient.Disconnect();
    Pause(3);
    //
    break;
}

What i'm doing wrong?
Thanks
Kobi