Exemplo n.º 1
0
        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());
                    }
                }
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 public override void Send(OutboundMessage message)
 {
     this.Socket.Send(message.ToBytes());
 }
Exemplo n.º 4
0
        public override void Send(OutboundMessage message)
        {
            ArraySegment <byte> buffer = new ArraySegment <byte>(message.ToBytes());

            Socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
        }
Exemplo n.º 5
0
 public virtual void Send(OutboundMessage message)
 {
     throw new NotImplementedException();
 }