public void SendMessageToOne(string data, int ClientID) { if (data.Length > 0) { AMessage sendMessage = new AMessage(MessageType.INFOTO1, ClientID, ClientID + ";" + data); binary.Serialize(stream, sendMessage); } }
public void SendMessage(MessageType type, string data) { if (data.Length > 0) { AMessage sendMessage = new AMessage(type, clientID, data); binary.Serialize(stream, sendMessage); } }
public void SendMessageToOne(AMessage sendMessage, int ClientNumber) { sendMessage.Type = MessageType.INFO; foreach (Client user in userList) { if (user.ClientNumber == ClientNumber) { binary.Serialize(user.Stream, sendMessage); user.Stream.Flush(); break; } } }
public AMessage ReceiveMessage() { try { AMessage recievedMessage = new AMessage(MessageType.ANY, 0, ""); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any,0); byte[] recievedData = client.Receive(ref endpoint); string message = Encoding.ASCII.GetString(recievedData); string[] recievedString = message.Split(';'); recievedMessage.ID = Convert.ToInt32(recievedString[0]); recievedMessage.Type = (MessageType)Enum.Parse(typeof(MessageType), recievedString[1]); recievedMessage.Message = message.Substring((recievedString[0] + ";" + recievedString[1] + ";").Length); return recievedMessage; } catch (Exception e) { messageQueue.Enqueue(new AMessage(MessageType.ERROR, clientID, "Faulty Message Recieved, Message Skipped. " + e.Message + " : " + e.TargetSite)); return null; } }
public void SendMessageToAll(AMessage sendMessage) { if (sendMessage.Type == MessageType.INFOEXCEPT1 || sendMessage.Type == MessageType.INFOTO1) sendMessage.Type = MessageType.INFO; foreach (Client user in userList) { binary.Serialize(user.Stream, sendMessage); user.Stream.Flush(); } }