-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathClientServerDemo.cs
41 lines (34 loc) · 1.17 KB
/
ClientServerDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using Avro.ipc;
using Avro.ipc.Specific;
using HelloAvro.DTO;
namespace HelloAvro
{
public class ClientServerDemo
{
private const string Hostname = "localhost";
public void Run()
{
Console.WriteLine("Running the Avro client server demo ...");
// Spawn server
var responder = new SpecificResponder<HelloAvroProtocol>(new Server());
var server = new SocketServer(Hostname, 0, responder);
server.Start();
Console.WriteLine("Server started on port {0}", server.Port);
// Spawn client(s)
var client = new Client(Hostname, server.Port);
bool onGoing = true;
do
{
client.Run();
Console.Write("Repeat client operations? (Y/N) ");
var keyPress = Console.ReadKey().KeyChar;
if (keyPress == 'n' || keyPress =='N')
onGoing = false;
} while (onGoing);
// Close the server to free up the port
server.Stop();
Console.WriteLine(Environment.NewLine + Helper.HorizontalLine);
}
}
}