Exemplo n.º 1
0
 public ClientHandler(SampleServer server, NetworkService service)
 {
     this.server  = server;
     this.service = service;
     service.OnMessageReceived += OnMessageReceived;
     service.OnServiceTeardown += OnServiceTeardown;
 }
Exemplo n.º 2
0
        public static void Main()
        {
            Console.InputEncoding  = System.Text.Encoding.Unicode;
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            Console.Write("start ([s]erver/client/[l]ocal): ");
            var option = Console.ReadLine();

            if (option.Length > 0 && option[0] == 's')
            {
                var server = new SampleServer();
                NetworkHelper.StartServer(server.OnClientConnected);
                Console.ReadLine();
            }
            else if (option.Length > 0 && option[0] == 'l')
            {
                var server = new SampleServer();
                NetworkHelper.StartServer(server.OnClientConnected);
                var service = NetworkHelper.StartClient("127.0.0.1");
                service.parseMessage = ParseMessage;
                var client = new SampleClient(service);
                client.Start();
            }
            else
            {
                var service = NetworkHelper.StartClient("s1.dotlab.cc");
                service.parseMessage = ParseMessage;                  // provide ParseMessage
                var client = new SampleClient(service);
                client.Start();
            }
        }