public void SendDDS() { int randomNumber = new Random().Next(0, Int32.MaxValue); this.TranslationDictionary = TCP_Protocoll.CreateDicForComm(randomNumber); this.Write(new TCP_Protocoll(TCP_Protocoll.HeaderData.DictonaryDefinitionsSeed, randomNumber)); }
public void Update() { Thread.Sleep(10); if (!this._socket.Connected) { _list.Remove(this); return; } if (this._socket.Available > 0) { TCP_Protocoll antwort = TCP_Protocoll.ReadMessage(this._inpStream, this.TranslationDictionary); if (antwort.ProtocolType == TCP_Protocoll.HeaderData.GoodBye) { Console.WriteLine("Client {0} says Goodbye. " + antwort.Data, this.ClientID); Disconnect(); } if (antwort.ProtocolType == TCP_Protocoll.HeaderData.DictonaryDefinitionsSeed) { this.TranslationDictionary = TCP_Protocoll.CreateDicForComm((int)antwort.Data); } if (this.Geantwortet != null) { this.Geantwortet(this, antwort); } } }
private static void Client_Geantwortet(TCP_Protocoll Antwort) { switch (Antwort.ProtocolType) { #region Hello Message case TCP_Protocoll.HeaderData.Hello: Console.WriteLine("Hello Message from Server: " + Antwort.Data); break; #endregion #region Error Message case TCP_Protocoll.HeaderData.Error: Console.WriteLine("Error in Communication"); break; #endregion #region CustomData Message case TCP_Protocoll.HeaderData.CustomData: Console.WriteLine("CusomtData from Server: " + Antwort.Data); break; #endregion #region Broadcast Message case TCP_Protocoll.HeaderData.Broadcast: Console.WriteLine("Broadcast from Server: " + Antwort.Data); break; #endregion #region DictonaryDef Message case TCP_Protocoll.HeaderData.DictonaryDefinitionsSeed: Console.WriteLine("Dictonary Definitions Seed: " + Antwort.Data); break; #endregion #region Goodbye Message case TCP_Protocoll.HeaderData.GoodBye: Console.WriteLine("Implement Your Def. here!"); break; #endregion default: Console.WriteLine("Hey Dev.! You realy should implement the following Enum!"); Console.WriteLine(Enum.GetName(typeof(TCP_Protocoll.HeaderData), Antwort.ProtocolType)); break; } }
public static void SendToAllClients(TCP_Protocoll protocol, int SenderID) { try { foreach (ServerClient cli in _list) { if (cli.ClientID != SenderID) { cli.Write(protocol); } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("EXCEPTION"); Console.WriteLine(ex.Message); Console.ForegroundColor = ConsoleColor.White; } }
private static void ClientAntwort(ServerClient Client, TCP_Protocoll Antwort) { Console.WriteLine("##--##--##--##--##--##--##--##--##--##--##"); string EnumName = Enum.GetName(typeof(TCP_Protocoll.HeaderData), Antwort.ProtocolType); switch (Antwort.ProtocolType) { case TCP_Protocoll.HeaderData.Error: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR"); Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Int-Type: " + ((int)Antwort.ProtocolType).ToString()); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; Client.Disconnect(); break; case TCP_Protocoll.HeaderData.Broadcast: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("BROADCAST"); ServerClient.SendToAllClients(Antwort, Client.ClientID); Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; break; default: Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; break; } }
public void Write(TCP_Protocoll protocol) { TCP_Protocoll.SendMessage(protocol, this.Writer, this.TranslationDictionary); }