SyncStream-不安定なチャネルを介してデータを送信するためのC#ライブラリ

最近、TCPを介してパケットでデータを送信するための簡単なプロトコルを実装した古い自作のライブラリを見つけました。

ファイルとノミで処理した後、ほとんど何も判明しませんでした (:



Meet-バギーチャンネル経由でデータを送信するためのSyncStreamライブラリ:







UPD:明らかに、チャネルがツイストペアとTCP / IPだけではないことは明らかではありません。 このライブラリは、一般的に、トランスポート(無線チャネルまたは赤外線ポート)に関係なく、インターフェイスクラスを記述して取得するだけで動作します。

UPD 2:Persistentの場合:ライブラリはTCP / IPに関連付けられていません



仕事の原理について



ソケットを作成するときにマルチプロトコルを実装するには、ソケット固有のConnect()、Close()、Bind()、Listen()、Send()、Receive()メソッドを含むBaseImplementation抽象クラスから派生したクラスを渡します。 その後、データの送信に直接関連するすべてのアクションは、このクラスを介して実行されます。

TCPを介した作業に対応するクラスは、すでにライブラリに含まれています。



データはパケットとして送信されます

パッケージに含まれるもの:







「余分な」データがチャネルに入るか、データの一部が失われたときに、次のパケットの開始を見つけるために「マジックシーケンス」が必要です(同期を復元します)。



楽しく楽しい使用について


クライアントコードの例:



Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  1. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  2. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  3. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  4. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  5. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  6. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  7. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  8. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  9. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  10. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  11. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  12. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  13. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  14. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  15. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  16. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  17. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }



  18. Copy Source | Copy HTML class MainClass { public static void Main( string [] args) { Socket s = new Socket ( new TcpImplementation ()); s.Receive += new Socket . ReceiveEvent (OnReceive); s.Connect( "127.0.0.1:1111" ); while ( true ) { string ss = Console .ReadLine(); Packet p = new Packet ( "message" , new Argument ( "text" , ss)); p.Important = true ; s.Send(p); } } public static void OnReceive( Socket s, Packet p) { Console .WriteLine( "<< " + p[ "text" ]); } }







ライブラリとソースをダウンロードできます。また、クライアントとサーバーのより複雑な例もここで見つけることができます。

GitHubリポジトリ

ZIPダイレクトリンク



All Articles