Ejemplo n.º 1
0
 public override void OnSent(MessageEventArgs e)
 {
     if (Sent != null)
     {
         Sent(e.Connection);
     }
     SentEvent.Set();
 }
Ejemplo n.º 2
0
 public override void OnReceived(MessageEventArgs e)
 {
     IMessage m = new Message();
     m.InnerMessage = new byte[e.Buffer.Length];
     Array.Copy(e.Buffer, m.InnerMessage, e.Buffer.Length);
     if (Received != null)
     {
         Received(e.Connection, m);
     }
     ReceivedEvent.Set();
     e.Connection.BeginReceive();
 }
Ejemplo n.º 3
0
        public override void OnReceived(MessageEventArgs e)
        {

            ChatMessage msg = DeserializeMessage(e.Buffer);

            switch (msg.MessageType)
            {

                case MessageType.mtLogin:

                    ((ConnectionData)e.Connection.CustomData).ConnectionState = ConnectionState.csAuthenticated;
                    ((ConnectionData)e.Connection.CustomData).UserName = msg.UserInfo[0].UserName;

                    msg.UserInfo[0].UserId = e.Connection.ConnectionId;
                    e.Connection.BeginSend(SerializeMessage(msg));
                    
                    msg.MessageType = MessageType.mtAuthenticated;
                    e.Connection.AsServerConnection().BeginSendToAll(SerializeMessage(msg), false);
                    
                    ISocketConnection[] cnns = e.Connection.AsServerConnection().GetConnections();
                    
                    if (cnns.Length > 0)
                    {
                        
                        bool send = false;
                        
                        msg.MessageType = MessageType.mtHello;
                        msg.UserInfo = new UserInfo[cnns.Length];
                        
                        for (int i = 0; i < cnns.Length; i++)
        			    {
                            
                            if (cnns[i] != e.Connection)
                            {
                                msg.UserInfo[i].UserName = ((ConnectionData)cnns[i].CustomData).UserName;
                                msg.UserInfo[i].UserId = cnns[i].ConnectionId;
                                send = true;
                            }
                            
		        	    }

                        if (send)
                        {
                            e.Connection.AsServerConnection().BeginSend(SerializeMessage(msg));
                        }
                        
                    }                    
                    
                    break;

                case MessageType.mtMessage:

                    e.Connection.AsServerConnection().BeginSendToAll(e.Buffer, false);

                    break;
                    
                    
                case MessageType.mtLogout:

                    e.Connection.AsServerConnection().BeginSendToAll(SerializeMessage(msg), false);
                    break;    
                
            }

            e.Connection.BeginReceive();

        }
Ejemplo n.º 4
0
        public override void OnSent(MessageEventArgs e)
        {

            //if (!e.SentByServer)
            //{
            //    e.Connection.BeginReceive();
            //}

        }
Ejemplo n.º 5
0
        public override void OnReceived(MessageEventArgs e)
        {

            StringBuilder s = new StringBuilder();

            s.Append("------------------------------------------------" + "\r\n");
            s.Append("Received - " + e.Connection.ConnectionId + "\r\n");
            s.Append(Encoding.GetEncoding(1252).GetString(e.Buffer) + "\r\n");
            s.Append("------------------------------------------------" + "\r\n");

            Event(s.ToString());

            s.Length = 0;

            SleepRandom(e.Connection.Host.HostType);

            if (e.Connection.Host.HostType == HostType.htServer)
            {
                e.Connection.BeginSend(e.Buffer);
            }
            else
            {
                byte[] b = GetMessage(e.Connection.SocketHandle.ToInt32());
                e.Connection.BeginSend(b);
            }

        }
Ejemplo n.º 6
0
        public override void OnSent(MessageEventArgs e)
        {

            if (!e.SentByServer)
            {
                
                StringBuilder s = new StringBuilder();

                s.Append("------------------------------------------------" + "\r\n");
                s.Append("Sent - " + e.Connection.ConnectionId + "\r\n");
                s.Append(Encoding.GetEncoding(1252).GetString(e.Buffer) + "\r\n");
                s.Append("------------------------------------------------" + "\r\n");

                Event(s.ToString().Trim());

                s.Length = 0;
                
             }

            if (e.Connection.Host.HostType == HostType.htServer)
            {
                
                if (!e.SentByServer)
                {
                    e.Connection.BeginReceive();
                }
                
            }
            else
            {
                e.Connection.BeginReceive();
            }

        }
Ejemplo n.º 7
0
 public virtual void OnReceived(MessageEventArgs e) { }
Ejemplo n.º 8
0
 public virtual void OnSent(MessageEventArgs e) { }
Ejemplo n.º 9
0
 public override void OnReceived(MessageEventArgs e)
 {
     FSocketClient.Enqueue(Encoding.GetEncoding(1252).GetString(e.Buffer));
     FSocketClient.SocketConnection.BeginReceive();
 }
Ejemplo n.º 10
0
 public override void OnSent(MessageEventArgs e)
 {
     FSocketClient.SentEvent.Set();
 }