@@ -63,6 +63,7 @@ private static void InitializeServer()
6363
6464 var scert = new X509Certificate2 ( "server.pfx" , "greenpass" ) ;
6565 server = new SecureProtoMessageServer ( port , scert ) ;
66+ server . StartServer ( ) ;
6667 server . OnMessageReceived += isFixedMessage ? EchoStatic : EchoDynamic ;
6768 Console . WriteLine ( "Server Running" ) ;
6869
@@ -198,272 +199,6 @@ private static void ShowStatus()
198199
199200}
200201
201- #region Old
202- //internal class Program1
203- //{
204- // static void Main(string[] args)
205- // {
206- // //BurstBench();
207- // //EchoBench();
208- // SecureProtoBench();
209- // }
210-
211- // private static void EchoBench()
212- // {
213- // long totMsgCl = 0;
214- // long totMsgsw = 0;
215- // Stopwatch sw = new Stopwatch();
216- // MessageEnvelope msg = new MessageEnvelope()
217- // {
218- // Header = "Test",
219- // Payload = new byte[32]
220-
221- // };
222-
223- // MessageEnvelope end = new MessageEnvelope()
224- // {
225- // Header = "Stop"
226- // };
227- // ConcurrentProtoSerialiser serialiser = new ConcurrentProtoSerialiser();
228-
229-
230-
231- // var server = new ProtoServer(20008, 100);
232- // server.OnMessageReceived += ServerStsReceived;
233-
234- // var clients = new List<ProtoClient>();
235- // for (int i = 0; i < 100; i++)
236- // {
237- // var client = new ProtoClient();
238- // client.OnMessageReceived += (reply) => ClientStsReceived(client, reply);
239-
240- // client.Connect("127.0.0.1", 20008);
241- // clients.Add(client);
242- // }
243-
244- // Task.Run(async () =>
245- // {
246- // long elapsedPrev = sw.ElapsedMilliseconds;
247- // long totMsgClPrev = 0;
248- // long totMsgswPrev = 0;
249- // while (true)
250- // {
251- // await Task.Delay(2000);
252- // long elapsedCurr = sw.ElapsedMilliseconds;
253- // int deltaT = (int)(elapsedCurr - elapsedPrev);
254- // Console.WriteLine("Elapsed: " + elapsedCurr);
255- // Console.WriteLine("client total message {0} server total message {1}", totMsgCl, totMsgsw);
256- // float throughput = (totMsgCl - totMsgClPrev + totMsgsw - totMsgswPrev) / (deltaT / 1000);
257-
258- // Console.WriteLine("Throughput :" + throughput.ToString("N1"));
259- // elapsedPrev = elapsedCurr;
260- // totMsgswPrev = totMsgsw;
261- // totMsgClPrev = totMsgCl;
262-
263- // }
264-
265- // });
266- // sw.Start();
267- // Parallel.ForEach(clients, client =>
268- // {
269- // for (int i = 0; i < 1000; i++)
270- // {
271- // client.SendAsyncMessage(msg);
272- // }
273- // //client.SendStatusMessage(end);
274-
275- // });
276-
277- // //var resp = clients[0].SendMessageAndWaitResponse(msg).Result;
278- // while (Console.ReadLine() != "e")
279- // {
280- // Console.WriteLine("client {0} server {1}", totMsgCl, totMsgsw);
281- // }
282- // Console.ReadLine();
283-
284-
285- // void ServerStsReceived(in Guid arg1, MessageEnvelope arg2)
286- // {
287- // Interlocked.Increment(ref totMsgsw);
288- // server.SendAsyncMessage(in arg1, arg2);
289- // }
290-
291- // void ClientStsReceived(ProtoClient client, MessageEnvelope reply)
292- // {
293- // Interlocked.Increment(ref totMsgCl);
294- // client.SendAsyncMessage(reply);
295-
296- // if (reply.Header.Equals("Stop"))
297- // {
298- // Console.WriteLine(sw.ElapsedMilliseconds);
299- // }
300- // }
301-
302-
303- // }
304-
305- // static void BurstBench()
306- // {
307- // int totMsgCl = 0;
308- // int totMsgsw = 0;
309- // Stopwatch sw = new Stopwatch();
310- // MessageEnvelope msg = new MessageEnvelope()
311- // {
312- // Header = "Test",
313- // Payload = new byte[32]
314-
315- // };
316-
317- // MessageEnvelope end = new MessageEnvelope()
318- // {
319- // Header = "Stop"
320- // };
321-
322- // ProtoServer server = new ProtoServer(20008, 100);
323- // server.OnMessageReceived += ServerStsReceived;
324-
325- // var clients = new List<ProtoClient>();
326- // for (int i = 0; i < 100; i++)
327- // {
328- // var client = new ProtoClient();
329- // client.OnMessageReceived += (reply) => ClientStsReceived(client, reply);
330-
331- // client.Connect("127.0.0.1", 20008);
332- // clients.Add(client);
333- // }
334-
335- // sw.Start();
336- // Parallel.ForEach(clients, client =>
337- // {
338- // for (int i = 0; i < 100000; i++)
339- // {
340- // client.SendAsyncMessage(msg);
341- // }
342- // client.SendAsyncMessage(end);
343-
344- // });
345-
346- // //var resp = clients[0].SendMessageAndWaitResponse(msg).Result;
347- // while (Console.ReadLine() != "e")
348- // {
349- // Console.WriteLine("client {0} server {1}", totMsgCl, totMsgsw);
350- // }
351- // Console.ReadLine();
352-
353-
354- // void ServerStsReceived(in Guid arg1, MessageEnvelope arg2)
355- // {
356- // Interlocked.Increment(ref totMsgsw);
357- // server.SendAsyncMessage(arg1, arg2);
358- // }
359-
360- // void ClientStsReceived(ProtoClient client, MessageEnvelope reply)
361- // {
362- // Interlocked.Increment(ref totMsgCl);
363- // if (reply.Header.Equals("Stop"))
364- // {
365- // Console.WriteLine(sw.ElapsedMilliseconds);
366- // }
367- // }
368-
369-
370- // }
371- // private static void SecureProtoBench()
372- // {
373- // int totMsgCl = 0;
374- // int totMsgsw = 0;
375- // Stopwatch sw = new Stopwatch();
376- // MessageEnvelope msg = new MessageEnvelope()
377- // {
378- // Header = "Test",
379- // Payload = new byte[32]
380-
381- // };
382-
383- // MessageEnvelope end = new MessageEnvelope()
384- // {
385- // Header = "Stop"
386- // };
387- // ConcurrentProtoSerialiser serialiser = new ConcurrentProtoSerialiser();
388-
389- // var scert = new X509Certificate2("server.pfx", "greenpass");
390- // var cert = new X509Certificate2("client.pfx", "greenpass");
391-
392- // SecureProtoServer server = new SecureProtoServer(20008, 100,scert);
393- // server.OnMessageReceived += ServerStsReceived;
394-
395- // var clients = new List<SecureProtoClient>();
396- // for (int i = 0; i < 100; i++)
397- // {
398- // var client = new SecureProtoClient(cert);
399- // client.OnMessageReceived += (reply) => ClientStsReceived(client, reply);
400-
401- // client.Connect("127.0.0.1", 20008);
402- // clients.Add(client);
403- // }
404-
405- // Task.Run(async () =>
406- // {
407- // long elapsedPrev = sw.ElapsedMilliseconds;
408- // int totMsgClPrev = 0;
409- // int totMsgswPrev = 0;
410- // while (true)
411- // {
412- // await Task.Delay(2000);
413- // long elapsedCurr = sw.ElapsedMilliseconds;
414- // int deltaT = (int)(elapsedCurr - elapsedPrev);
415- // Console.WriteLine("Elapsed: " + elapsedCurr);
416- // Console.WriteLine("client total message {0} server total message {1}", totMsgCl, totMsgsw);
417- // float throughput = (totMsgCl - totMsgClPrev + totMsgsw - totMsgswPrev) / (deltaT / 1000);
418-
419- // Console.WriteLine("Throughput :" + throughput.ToString("N1"));
420- // elapsedPrev = elapsedCurr;
421- // totMsgswPrev = totMsgsw;
422- // totMsgClPrev = totMsgCl;
423-
424- // }
425-
426- // });
427- // sw.Start();
428- // Parallel.ForEach(clients, client =>
429- // {
430- // for (int i = 0; i < 1000; i++)
431- // {
432- // client.SendAsyncMessage(msg);
433- // }
434- // //client.SendStatusMessage(end);
435-
436- // });
437-
438- // //var resp = clients[0].SendMessageAndWaitResponse(msg).Result;
439- // while (Console.ReadLine() != "e")
440- // {
441- // Console.WriteLine("client {0} server {1}", totMsgCl, totMsgsw);
442- // }
443- // Console.ReadLine();
444-
445-
446- // void ServerStsReceived(in Guid arg1, MessageEnvelope arg2)
447- // {
448- // Interlocked.Increment(ref totMsgsw);
449- // server.SendAsyncMessage(in arg1, arg2);
450- // }
451-
452- // void ClientStsReceived(SecureProtoClient client, MessageEnvelope reply)
453- // {
454- // Interlocked.Increment(ref totMsgCl);
455- // client.SendAsyncMessage(reply);
456-
457- // if (reply.Header.Equals("Stop"))
458- // {
459- // Console.WriteLine(sw.ElapsedMilliseconds);
460- // }
461- // }
462-
463-
464- // }
465- //}
466- #endregion
467202
468203
469204
0 commit comments