예제 #1
0
 public override void OnSent(MessageEventArgs e)
 {
     if (Sent != null)
     {
         Sent(e.Connection);
     }
     SentEvent.Set();
 }
예제 #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();
 }
예제 #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();

        }
예제 #4
0
        public override void OnSent(MessageEventArgs e)
        {

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

        }
예제 #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);
            }

        }
예제 #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();
            }

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