示例#1
0
        public override void OnSent(MessageEventArgs e)
        {
            if (!e.SentByServer)
            {
                StringBuilder s = new StringBuilder();

                s.Append("------------------------------------------------" + "\r\n");
                s.Append("Sent - " + e.Connection.Context.ConnectionId + "\r\n");
                s.Append("Sent Bytes - " + e.Connection.Context.WriteBytes.ToString() + "\r\n");
                s.Append("------------------------------------------------" + "\r\n");

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

                s.Length = 0;
            }

            if (e.Connection.Context.Host.Context.HostType == HostType.htServer)
            {
                if (!e.SentByServer)
                {
                    e.Connection.BeginReceive();
                }
            }
            else
            {
                e.Connection.BeginReceive();
            }
        }
示例#2
0
        public override void OnReceived(MessageEventArgs e)
        {
            StringBuilder s = new StringBuilder();

            s.Append("------------------------------------------------" + "\r\n");
            s.Append("Received - " + e.Connection.Context.ConnectionId + "\r\n");
            s.Append("Received Bytes - " + e.Connection.Context.ReadBytes.ToString() + "\r\n");
            s.Append("------------------------------------------------" + "\r\n");

            Event(s.ToString());
            s.Length = 0;

            SleepRandom(e.Connection.Context.Host.Context.HostType);

            if (e.Connection.Context.Host.Context.HostType == HostType.htServer)
            {
                e.Connection.BeginSend(e.Buffer);
            }
            else
            {
                byte[] b = GetMessage(e.Connection.Context.SocketHandle.Handle.ToInt32());
                e.Connection.BeginSend(b);
            }
        }
 public override void OnSent(MessageEventArgs e)
 {
     FSocketClient.SentEvent.Set();
 }
 public override void OnReceived(MessageEventArgs e)
 {
     FSocketClient.Enqueue(Encoding.GetEncoding(1252).GetString(e.Buffer));
     FSocketClient.SocketConnection.BeginReceive();
 }
示例#5
0
 public override void OnSent(MessageEventArgs e)
 {
     //if (!e.SentByServer)
     //{
     //    e.Connection.BeginReceive();
     //}
 }
示例#6
0
        public override void OnReceived(MessageEventArgs e)
        {
            ChatMessage msg = DeserializeMessage(e.Buffer);

            switch (msg.MessageType)
            {
                case MessageType.mtLogin:

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

                    msg.UserInfo[0].UserId = e.Connection.Context.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 != null) && (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].Context.UserData).UserName;
                                msg.UserInfo[i].UserId = cnns[i].Context.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();
        }