private static void AppServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { switch (requestInfo.Key.ToUpper()) { case ("ECHO"): session.Send(requestInfo.Body); break; case ("ADD"): session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString()); break; case ("MULT"): var result = 1; foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p))) { result *= factor; } session.Send(result.ToString()); break; } }
/// <summary> /// 客户端接收的数据 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> void appServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Thread.Sleep(300); var key = requestInfo.Key; var body = requestInfo.Body; string str = $"接收消息:Session:{session.SessionID}, key:{key}, body:{body}"; // LogSingleton.LogHelper.Info("Received-" + str); appServer.Logger.Info("Received-" + str); Console.WriteLine(str); string str1 = $"{new Random().Next(1, 999)} {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}\r\n"; // LogSingleton.LogHelper.Info("Send-" + str1); appServer.Logger.Info("Send-" + str1); Console.WriteLine($"{session.SessionID}-{str1}"); session.Send(Encoding.Default.GetBytes(str1), 0, str1.Length); //switch (key) //{ // case "1": // Console.WriteLine("hello word"); // break; // case "2": // Console.WriteLine("LOL"); // break; // case "3": // Console.WriteLine(body); // session.Send(body + "--已处理"); // break; // default: break; //} }
private void Server_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { //requestInfo.Key 是请求的命令行用空格分隔开的第一部分 //requestInfo.Parameters 是用空格分隔开的其余部分 TraceLog.WriteLine(requestInfo.Body); switch (requestInfo.Key.ToUpper()) { case ("ECHO"): session.Send(requestInfo.Body); break; case ("ADD"): session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString()); break; case ("MULT"): var result = 1; foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p))) { result *= factor; } session.Send(result.ToString()); break; } }
protected override void HandleUnknownRequest(SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { MsgUtil.Send(this, new MsgInfo(MsgType.SEND_RESULT) { Success = false, Message = "Unknown request: " + requestInfo.Key }); }
/// <summary> /// 接收到新数据 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> private void AppServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { StringBuilder sb = new StringBuilder(); sb.Append(requestInfo.Key); foreach (var item in requestInfo.Parameters) { sb.Append(" " + item); } string data = sb.ToString(); ProcessReceivedData(session, data); }
/// <summary> /// 接收到客户端发送的请求 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> static void appServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { var key = requestInfo.Key; if (key != null) { key = key.Replace("\r\n", "").Replace("\n", ""); } var body = requestInfo.Body; if (body != null) { body = body.Replace("\r\n", "").Replace("\n", ""); } switch (key) { case "1": Console.WriteLine("hello word"); break; case "2": Console.WriteLine("LOL"); break; case "3": body = Base64Util.decode(body); Console.WriteLine("case3:" + body); string txt = "key:" + key + " body:" + body; txt = Base64Util.encode(txt); session.Send(txt); break; default: Console.WriteLine("key:" + key + " body:" + body); break; } // Console.WriteLine("session id:" + session.SessionID); }
private void AppServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { throw new NotImplementedException(); }
/// <summary> /// 与Command互斥 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> private void CustomServer_NewRequestReceived(CustomSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { TraceLog.WriteLine("CustomServer_NewRequestReceived...", logger: _logger); }
private void Server_NewRequestReceived(Session session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Console.WriteLine(requestInfo.Key); }
static void appServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Console.WriteLine("appServer_NewRequestReceived" + session.SessionID); }
public override void ExecuteCommand(SuperSocket.SocketBase.AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Console.WriteLine("cmd-------------" + requestInfo.Body); }
public override void ExecuteCommand(MySession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Thread.Sleep(6000); session.Send("Test CommandFilter!"); }
private void AppServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { int ParametersAmount = requestInfo.Parameters.Length; Client sender = Clients .Find(x => x.session == session); string senderName = sender.name; if (requestInfo.Key == BASE_CORE) { if (ParametersAmount == 2 && requestInfo.Parameters[0] == "Register") { string pluginName = requestInfo.Parameters[1]; if (pluginName != "Base\\Core" && Clients.FindIndex(x => x.name == pluginName) == -1) { Clients.Find(x => x.session == session).name = pluginName; session.Send("M" + BASE_CORE + " Registered " + pluginName); } else { session.Send("M" + BASE_CORE + " RegistrationNameTaken"); } } else if (ParametersAmount == 2 && requestInfo.Parameters[0] == "IsLoaded") { string pluginName = requestInfo.Parameters[1]; Client[] c = Clients .Where(x => x.name == pluginName) .ToArray(); string result = c.Length > 0 && c[0].ready ? " Loaded " + pluginName : " NotLoaded " + pluginName; session.Send("M" + BASE_CORE + result); } else if (ParametersAmount == 1 && requestInfo.Parameters[0] == "Ready") { if (senderName == null) { session.Send("M" + BASE_CORE + " NotRegistered"); } else { sender.ready = true; Broadcast(BASE_CORE, "Ready " + senderName); session.Send("M" + BASE_CORE + " Ready " + senderName); } } else if (ParametersAmount == 1 && requestInfo.Parameters[0] == "Shutdown") { if (senderName == null) { session.Send("M" + BASE_CORE + " NotRegistered"); } else { Broadcast("Base\\Log", "Shutdown triggered by " + senderName); appServer.Stop(); waitForExit.Set(); } } } else if (senderName != null) { SendMessage(senderName, requestInfo.Key, requestInfo.Body); } }