Forum

You must be logged in to post Login


Lost Your Password?

Search Forums:


 






Wildcard Usage:
*    matches any number of characters
%    matches exactly one character

TCP Server

No Tags
UserPost

12:56 pm
October 31, 2011


mikeluckham

New Member

posts 2

Thanks for your work on this software.

What is the purpose of UseSynchronousCommunication, it is used only in conjunction with ReceiveDataInline and appears to instantiate multiple threads for receiving data.

I have tried UseSynchronousCommunication 'true' and 'false' and still can connect multiple clients.

Second, is it possible for the server to reply to a message – whether UDP or TCP?

Mike

1:56 pm
October 31, 2011


Paul

Admin

posts 49

Hello Mike,

Connecting with multiple clients is independent of the UseSynchronousCommunication flag. That flag is specifically TCP-related and determines whether to use the TcpConnection DataReceivedCallback mechanism or to create data receive threads directly within the TcpServer class.

If you create data receive threads within the TcpServer, the SynchronousReceiveData() method invoked by those threads makes synchronous (blocking) data reads. That's opposite from the asynchoronous calls invoked within the TcpConnection class — hence the name UseSynchronousCommunication.

That flag is turned off (in the released package) for the OscServer's instantiation of TcpServer so that we get async data reception (which is better for gracefully terminating multiple Tcp connections).

But again, this is independent of multiple clients connecting to an OscServer instance. I've just verified that functionality on my machine (for both TCP and UDP) and it worked great. To do that on your side, there's no need to modify the underlying libraries. If you're using the OscDemo application, just change the two Program.cs files in the Client and Server projects to use Tcp as the TransportType and change the destination to say, IPAddress.Loopback (i.e. 127.0.0.1). Finally, make sure your OscServer's TransmissionType is Unicast. Then kick off one Receiver (the Client project) and multiple Transmitters (the Server project).

To your question of replies to messages — this is absolutely possible, but it's not as simple as toggling a flag or anything. You simply need to create an OscServer on the "Transmitter" side that listens for response messages. Then the handler of your original OscServer (the "Receiver") would send messages to either an agreed upon port, or you could send the "return message" port during an initial Transmitter-Receiver communication. If you're interested in an example, my Multi-Touch Framework does exactly this for Heartbeats between client and server using Osc.

Shout if you have questions.

Paul

 

10:20 am
November 1, 2011


mikeluckham

New Member

posts 2

Thanks for your fast and complete explanation Paul, and yes – multiple Tcp clients to one server do work regardless of the UseSynchronousCommunication setting.

Considering the situation of replies, for my purposes it seems best to adopt a 'mailbox' model where each process 'server' listens to a well-known port.

In the past I have developed applications using Tcp for lengthy connections (many minutes) wanting a model where a point-to-point bi-directional connection could be established simply and maintained reliably, the applications at each end being notified only if the connection was broken.  Like a pipe, I suppose.

I found that trying to make the Tcp layer sufficiently robust in the face of connection setup/network delays, NAT routers, etc so that the application-level code could remain ignorant of transmission delays/timeouts/disconnects/lengthy notification period after disconnect/etc … is – challenging.  Particularly annoying was the need for application-level KeepAlive messages and responses, to keep the channel "active" thus suggesting to routers not to take down "idle" communication channels.  So although Tcp guarantees in-sequence packet delivery and exhaustive retries, those seem to be its only benefits.

For that reason, and considering the simple model of Osc-type communication is why I chose to use it – I think UDP is best for my purposes.

No Tags

About the Bespoke Software forum



No Comment

Comments are closed.