Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Guess I'll answer my own question.</p> <p>I implemented the solution my self.</p> <p>Key points to my solution:</p> <p>A class named IPClient which wraps up a TcpClient instance, uses async model of calling TcpClient.BeginConnect, BeginRead, etc. It has a Timer used for reconnecting if it loses connection. This is the class that connects to the device.</p> <p>It's public interface would look something like this:</p> <pre><code>public class IPClient{ public event EventHandler&lt;MyConnectedArgs&gt; Connected; public event EventHandler&lt;MyDisconnectedArgs&gt;Disconnected; public event EventHandler&lt;MyDataReceivedArgs&gt; DataReceived; public bool Connect(string address, int port){...} public bool Disconnect() {...} } </code></pre> <p>To open the port that would allow other clients to connect, I used this library: <a href="http://codeproject.com/KB/IP/BasicTcpServer.aspx" rel="nofollow">http://codeproject.com/KB/IP/BasicTcpServer.aspx</a> and modified it a bit.</p> <p>It's job was to open a port, accept connections, and do the following:</p> <ol> <li> in the Connected handler, start the listening port</li> <li> in the Disconnected handler, stop the listening port</li> <li> in the DataReceived handler, broadcast the data to any connected clients.</li> </ol> <p>I'll leave out the rest of the boring details, but say it wasn't "too hard", and eventually I just had to roll my own.</p> <p>command line usage: myapp.exe remote_addr remote_port listen_port</p> <p>psuedocode/main idea of my program main:</p> <pre><code>static int Main(string[] args){ //SetConsoleCtrlHandler(my callback re: ctrl+C,etc) //get command line params var ipClient = new IPClient(); var myprovider = MyTcpServiceProvider(); var server = new TcpServer(myProvider, listenPort); ipClient.Connected += (sender, e) =&gt; server.Start(); ipClient.Disconnected += (sender,e) =&gt; server.Stop(); ipClient.DataReceived += (sender,e)=&gt; provider.BroadcastToClients(e.Data); ipClient.Connect(remoteAddress, remotePort); //wait for Ctrl+C or program exit //shutdown code,etc return 0; } </code></pre>
    singulars
    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. This table or related slice is empty.
 

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