Note that there are some explanatory texts on larger screens.

plurals
  1. PODriving events across custom TCP Long-Polling server
    primarykey
    data
    text
    <p>I’m trying to write a custom TCP based long polling server that will serve as a go-between for other TCP connections that require more persistence than a mobile phone can provide.</p> <p>The way I’m trying to do it is writing an asynchronous TCP server in C# and a matching TCP Client also written in C#.</p> <p>The way that long polling works (as far as I understand it) is that you open a TCP connection to a server, and the server Halts before sending data back across the socket. You find a Heartbeat interval that works on a mobile phone network (I’ve heard that around 8 minutes works?) and you send an empty packet if there is no updated data.</p> <p>This is where my trouble comes in. I can’t figure out how to “link” my client’s request for data with an event handler running on the server… </p> <p>The flow should be something like this (“client” is on a phone):</p> <ol> <li><p>User starts my application</p></li> <li><p>Client sends a request to be notified if data has changed</p></li> <li><p>Server “links” (registers) client’s socket object into an “Event handler” that is called by the server’s other TCP connections that I talked about! </p></li> <li><p>Event</p> <p>o If it is triggered (new data has arrived), Send the data to the client</p> <p>o If it isn’t triggered (no new data), Send an “EmptyChanges” packet to client</p></li> <li><p>Client receives data on the phone and processes it (calls an event handler based on what type of packet it received and passes the “data” it got from the server to it)</p></li> <li><p>Client sends a request to be notified if data has changed</p></li> </ol> <p>So, my problem is that I can’t think of a design that will accomplish what I want it to do. The problem is that I don’t know HOW to do #3. How do I “Link” one event handler from another? And these are almost guaranteed to be running on different threads!</p> <p>So, my application would look something like this (all psuedocode):</p> <pre><code>Class AppClass { Main() List&lt;Client&gt; clients; List&lt;DataServers&gt; dataServers; DataReceivedFromServer(Data stuff) { } MessageReceivedFromPhone(PhoneMessage pm, object sender) { //Loop here until HeartBeat interval reached Int totalTime = 0; While(totalTime &lt; HEARTBEAT_INTERVAL) { If( ) // If we have received data from the server, and the client WANTED that data, send it now { } } } } </code></pre> <p>Kind of? I want it to be event driven, but I'm having the damndest time figuring out how to drive the application with a PUSH driven style vs. what I'm "used" to of Polling.</p> <p>Please, be kind as I might be doing something overly complicated and stupid because this is my first real attempt at using Socket programming (never needed it) and it's especially hard due to the nature of Cell phones being on transient networks and my server needing to maintain the location of these phones with an OPEN TCP connection.</p> <blockquote> <p>Server platform: Windows </p> <p>Server language: C#</p> <p>Test Client platform: Windows </p> <p>Test Client language: C#</p> <p>Target Client platform: Windows Mobile 6.5, iPhone, Android (clients will be written separately)</p> <p>Target client language: C#, Obj-C or MonoTouch, Java</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CODo all the clients need to receive the same data or is the data different for every client ? If the data is the same, a simple broadcast could be the easiest way: You simply "mark" your client as " listener " (simple boolean isListener or something) and then when data comes, you simple loop through the list of clients sending them the data
      singulars
    2. COBy The Way: This sounds a lot like a Message Queue. We have a similar thing running here for a completely different purpose but the idea is the same. You could use ActiveMQ message broker and simply set your phone to listen to a certain topic. On event you send the message (data) on that topic. As a bonus, the connection with ActiveMQ is pretty stable (using their client) and you don't have to dive into the illuster world of keeping tcp connections on bad network / cellphone connections which can be a real PITA
      singulars
    3. CO@Noctris: That ActiveMQ looks very VERY interesting. Pending more research, I think you may have found exactly what I was looking for, I was just not sure how to put what I needed into standard terms and such. I'll read up more about specific ActiveMQ Transport (I think they used the term Publisher) layer implementation, and if I can customize it how I need it then it would be perfect!
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload