public override void OnSent(MessageEventArgs e) { if (Sent != null) { Sent(e.Connection); } SentEvent.Set(); }
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(); }
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(); }
public override void OnSent(MessageEventArgs e) { //if (!e.SentByServer) //{ // e.Connection.BeginReceive(); //} }
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); } }
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(); } }
public virtual void OnReceived(MessageEventArgs e) { }
public virtual void OnSent(MessageEventArgs e) { }
public override void OnReceived(MessageEventArgs e) { FSocketClient.Enqueue(Encoding.GetEncoding(1252).GetString(e.Buffer)); FSocketClient.SocketConnection.BeginReceive(); }
public override void OnSent(MessageEventArgs e) { FSocketClient.SentEvent.Set(); }