public void BroadCastMessage(OutboundMessage byteMsg) { foreach (IClient receiver in this.Clients) { lock (receiver) { bool isTcpClient = receiver is TcpClient; //clear the users current input and print //this will keep the chat feeling async and easier to read if (isTcpClient) { receiver.Send(Encoding.ASCII.GetBytes("\x1b[2K")); //clear line receiver.Send(Encoding.ASCII.GetBytes("\r")); //move cursor to start of line } receiver.Send(byteMsg); if (isTcpClient) { char soundNotification = (char)7;//makes a sound letting user know chatroom has new dialog //reprint the users input receiver.Send(Encoding.ASCII.GetBytes(soundNotification + "\r=> ")); receiver.Send(receiver.CurrentBytesSentWithoutNewLine.ToArray()); } } } }
public void SendActiveRoomsTo(IClient client) { try { client.Send(new OutboundMessage("Active rooms are:")); foreach (ChatRoom chatRoom in this.Chatrooms) { OutboundMessage message = new OutboundMessage( "* " + chatRoom.Name + " (" + chatRoom.Clients.Count + ")"); client.Send(message); } client.Send(new OutboundMessage("end of list.")); client.Send(new OutboundMessage("type: /join [chatroomname]")); } catch (SocketException) { return; throw; } }
public override void Send(OutboundMessage message) { this.Socket.Send(message.ToBytes()); }
public override void Send(OutboundMessage message) { ArraySegment <byte> buffer = new ArraySegment <byte>(message.ToBytes()); Socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None); }
public virtual void Send(OutboundMessage message) { throw new NotImplementedException(); }