diff options
author | Halil İbrahim Kalkan <hi_kalkan@yahoo.com> | 2013-04-08 21:44:58 +0300 |
---|---|---|
committer | Halil İbrahim Kalkan <hi_kalkan@yahoo.com> | 2013-04-08 21:44:58 +0300 |
commit | 79953cb56cda204f190ffcd9995b27ebea25e62d (patch) | |
tree | de939755c2e32eaa5fa3e41e21114e1c727ed0a4 /performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs | |
parent | 934c543eb6b0bd7173038e45a7dac0241d091da4 (diff) | |
download | scs-79953cb56cda204f190ffcd9995b27ebea25e62d.zip scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.gz scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.bz2 |
Adding to github
Adding to github
Diffstat (limited to 'performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs')
-rw-r--r-- | performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs b/performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs new file mode 100644 index 0000000..88eafd9 --- /dev/null +++ b/performance-tests/Messaging/ServerApp/DuplexServerCustomProtocol.cs @@ -0,0 +1,53 @@ +using System; +using System.Diagnostics; +using CommonLib; +using Hik.Communication.Scs.Communication.EndPoints.Tcp; +using Hik.Communication.Scs.Communication.Messages; +using Hik.Communication.Scs.Server; + +namespace ServerApp +{ + public class DuplexServerCustomProtocol + { + private static int _messageCount; + private static Stopwatch _stopwatch; + + public static void Run() + { + var server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(10033)); + + server.WireProtocolFactory = new MyWireProtocolFactory(); + server.ClientConnected += server_ClientConnected; + + server.Start(); + + Console.WriteLine("Press enter to stop server"); + Console.ReadLine(); + + server.Stop(); + } + + static void server_ClientConnected(object sender, ServerClientEventArgs e) + { + e.Client.MessageReceived += Client_MessageReceived; + } + + static void Client_MessageReceived(object sender, MessageEventArgs e) + { + ++_messageCount; + + var client = (IScsServerClient) sender; + client.SendMessage(new ScsTextMessage("Hello from server!")); + + if (_messageCount == 1) + { + _stopwatch = Stopwatch.StartNew(); + } + else if (_messageCount == Consts.MessageCount) + { + _stopwatch.Stop(); + Console.WriteLine(Consts.MessageCount + " message is received in " + _stopwatch.Elapsed.TotalMilliseconds.ToString("0.000") + " ms."); + } + } + } +} |