public static Paket Receive(Socket socket) { byte[] sizeBuffer = new byte[4]; int recBytes = 0; while ((recBytes += socket.Receive(sizeBuffer, recBytes, sizeBuffer.Length - recBytes, SocketFlags.None)) != 4) { } Paket newPaket = new Paket(); uint newSize = BitConverter.ToUInt32(sizeBuffer, 0); byte[] buffer = new byte[newSize]; recBytes = 0; while ((recBytes += socket.Receive(buffer, recBytes, buffer.Length - recBytes, SocketFlags.None)) < newSize) { } newPaket.Commando = BitConverter.ToUInt32(buffer, 0); byte[] tempbuffer = new byte[buffer.Length - 4]; for (int i = 4; i < buffer.Length - 4; i++) { tempbuffer[i - 4] = buffer[i]; } newPaket.data = tempbuffer; return(newPaket); }
public Paket Receive(string ClientName) { if (Connected_Sockets.ContainsKey(ClientName)) { return(Paket.Receive(Connected_Sockets[ClientName])); } else { throw new Exception("Client nicht vorhanden"); } }
public void Send(string ClientName, Paket paket) { if (Connected_Sockets.ContainsKey(ClientName)) { paket.Send(Connected_Sockets[ClientName]); } else { throw new Exception("Client nicht vorhanden"); } }
public void ParsePaket(Paket paket) { kk.Add(Commands.Disconnect); //switch(paket.Command) //{ // case Commands.SendMsg: // if(RegisteredCommands.ContainsKey(Commands.SendMsg)) // { // int Count = RegisteredCommands[Commands.SendMsg].Count; // if (Count > 0) // { // for (int i = 0; i < Count; i++) // { // RegisteredCommands[Commands.SendMsg][i](paket.Getdata()); // } // } // } // break; // case Commands.SendPMsg: // if (RegisteredCommands.ContainsKey(Commands.SendMsg)) // { // int Count = RegisteredCommands[Commands.SendMsg].Count; // if (Count > 0) // { // for (int i = 0; i < Count; i++) // { // RegisteredCommands[Commands.SendMsg][i](paket.Getdata()); // } // } // } // break; // case Commands.SetName: // if (RegisteredCommands.ContainsKey(Commands.SendMsg)) // { // int Count = RegisteredCommands[Commands.SendMsg].Count; // if (Count > 0) // { // for (int i = 0; i < Count; i++) // { // RegisteredCommands[Commands.SendMsg][i](paket.Getdata()); // } // } // } // break; // case Commands.Disconnect: // if (RegisteredCommands.ContainsKey(Commands.SendMsg)) // { // int Count = RegisteredCommands[Commands.SendMsg].Count; // if (Count > 0) // { // for (int i = 0; i < Count; i++) // { // RegisteredCommands[Commands.SendMsg][i](paket.Getdata()); // } // } // } // break; //} }