static void Main(string[] args) { Task.Run(() => { Connection server = new Connection(ConnectionMode.Server, new IPEndPoint(IPAddress.Any, 12344)); EdtClient serverGateway = new EdtClient(server); string path = @"D:\Plutonist\Pictures\Received.jpeg"; using (FileStream fs = File.OpenWrite(path)) { while (serverGateway.ServerControls.Count > 0) { serverGateway.ServerControls.First().Value.DataControl.Receiver.OutputStream = fs; } } }); Task.Run(async() => { Connection client = new Connection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12344)); EdtClient clientGateway = new EdtClient(client); await Task.Delay(2000); string path = @"D:\Plutonist\Pictures\20151111213448_hCFe5.jpeg"; using (FileStream fs = File.OpenRead(path)) { await clientGateway._clientControl.DataControl.Sender.WriteDataAsync(fs); } }); Console.ReadKey(); }
/// <summary> /// Handle the ping packet sent from client and create ServerControl for new client. /// </summary> /// <param name="pingPacket"></param> /// <param name="clientIPEndPoint"></param> private void HandlePingPacket(PingPacket pingPacket, IPEndPoint clientIPEndPoint) { int clientId = pingPacket.ClientId; // Whether is a new client if (clientId == 0) { ServerControl serverControl = new ServerControl(Conn, clientIPEndPoint); EdtClient edtClient = new EdtClient(serverControl); clientId = serverControl.ClientId; EdtClients.Add(clientId, edtClient); Console.WriteLine("A Client connected in: {0} - {1}", clientId, clientIPEndPoint.ToString()); OnClientConnect?.Invoke(edtClient); } EdtClients[clientId].ServerControl.OnPing(pingPacket); }