public Client(Socket clientSocket) { this.clientSocket = clientSocket; this.clientThread = new Thread(IncomingDataTask); this.id = Guid.NewGuid().ToString(); this.InputData = new Input(); this.clientThread.Start(new Tuple<Socket,Input>(clientSocket,InputData)); }
private static void DataManager(Packet packet, Input input) { switch (packet.packetType) { case (PacketType.Registration): //should never happen. break; case (PacketType.Movement): input.InputDirection.x = float.Parse(packet.stringData[0]); input.InputDirection.y = float.Parse(packet.stringData[1]); Server.Informer.AddEventInformation("Movement pakke modtaget!",2); break; } }
public MyServer(int port, string username, string password, MainWindow w) { try { exch = new ECDiffieHellmanCng(256); exch.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash; exch.HashAlgorithm = CngAlgorithm.Sha256; publicKey = exch.PublicKey.ToByteArray(); this.username = username; this.password = password; this.Window = w; input = new Input(); mcb = new MyClipBoard(); localpt = new IPEndPoint(IPAddress.Any, port); /* Initializes the Listener */ myList = new TcpListener(localpt); uclient = new UdpClient(); uclient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); uclient.DontFragment = true; uclient.Client.Bind(localpt); /* Start Listening at the specified port */ myList.Start(); Console.WriteLine("The server is running at port 8001..."); Console.WriteLine("The local End point is :" + myList.LocalEndpoint); Console.WriteLine("Waiting for a connection....."); Thread t3 = new Thread(InputProcessing); t3.Start(); Thread t = new Thread(ClipBoardProcessing); //LOGIN AND CLIPBOARD PROCESSING t.SetApartmentState(ApartmentState.STA); t.Start(); } catch (SocketException se) { if (se.ErrorCode == 10048) { throw se; } Console.WriteLine(se.Message + " " + se.ErrorCode); } catch (Exception e) { Console.WriteLine(e.Message); } }