using SuperSocket.SocketBase; using SuperSocket.SocketBase.Protocol; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Api.Framework.Tools { public enum SocketCMD:int { Wechat登陆成功 = 1, Wechat收到消息 = 2 } public class SuperSocketServer { public AppServer Server { get;private set; } public SuperSocketServer() { } public void Stop() { if (this.Server != null) { this.Server.Stop(); } } public bool Start(int port) { this.Stop(); this.Server = new AppServer(); if (!Server.Setup(port)) return false; //Try to start the appServer if (!Server.Start()) return false; Server.NewSessionConnected += new SessionHandler(appServer_NewSessionConnected); Server.SessionClosed += appServer_NewSessionClosed; //SocketCMD 是KEY Server.NewRequestReceived += new RequestHandler(appServer_NewRequestReceived); return true; } private void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo) { try { var cmd = Util.ConvertEnum(int.Parse(requestInfo.Key)); switch (cmd) { case SocketCMD.Wechat登陆成功: break; case SocketCMD.Wechat收到消息: break; default: break; } } catch (Exception) { } } private void appServer_NewSessionClosed(AppSession session, CloseReason value) { } private void appServer_NewSessionConnected(AppSession session) { } } }