locked
Accepting multiple TCP/IP clients RRS feed

  • Question

  •  I am trying to write an MSRS interface to an existing robot software system so that a simulated robot can be used in place of the hardware. The (linux c) code that I am attempting to port to MSRS is multithreaded with a thread devoted to accepting new client connections. I have some C# code that will accept a single client connection, but it runs on a timer, and I would prefer to not have a constantly spinning thread in the background.

     

     Is there a good way to fit this into a service? Can the tcp/ip connection be handled in a way similar to the serial port in robotics tutorial 6? Any suggested references?

     

     Thanks,

    John

    Tuesday, August 7, 2007 4:27 PM

Answers

  • Hi, you can add your open sockets to a list you keep as a field of your service implementaion class ( a private field) No need for this list of sockets to be on anything serializable (like your state class). Remember, that the service handler protect access to the code inside the handler, they dont care what state, field etc you are accessing.

     

    g

    Sunday, August 12, 2007 8:17 AM

All replies

  • sure, you can create a service that listen on TCP connections. Since DSS usually handles all networking, is there a reason why you want to go straight down to TCP, from a service? Is it because you have some remote PC/hardware that only talks TCP currently?

     

    If you haveto do TCP use the TCPListener class in asynchronous mode. Then no thread is really blocked waiting for connections. Documentaion on TCPListener is available on MSDN.

     

    Then, like you mentioned, robotics tutorial 6 applies: Instead of serial, you have a service that talks TCP on one side and exposes a full MSRS style contract on the other

     

    g

    Friday, August 10, 2007 3:51 AM
  •  I have a number of remote (linux) machines that all communicate with what is essentially a robot server. The server is the part that I am porting into MSRS, so I must listen and reply to multiple clients over TCP. It is not practical for me to port the higher level control code for now.

     

     I have started with Sockets using BeginAccept and BeginRead, which seems to work for incoming messages, but  I want to use CCR to protect the service's state information and I am not sure how to send a reply (after altering the state) to the correct socket/client from a servicehandler. I have tried adding a Socket datamember to the class to be handled by the servicehandler, but this results in a compilation error (No overload for method Socket takes '0' arguments). Is this a reasonable approach? Is there a better way of replying to a particular client after allowing CCR to handle state access?

     

     Thanks for the information on TCPListener

    Friday, August 10, 2007 2:45 PM
  • Hi, you can add your open sockets to a list you keep as a field of your service implementaion class ( a private field) No need for this list of sockets to be on anything serializable (like your state class). Remember, that the service handler protect access to the code inside the handler, they dont care what state, field etc you are accessing.

     

    g

    Sunday, August 12, 2007 8:17 AM
  •  I was not sure that non-state variables would be protected within exclusive handlers. Keeping a list of clients and including indicies in the bodies of the ports appears to work.

     

     Thanks again,

    Monday, August 13, 2007 2:55 PM