private void InitForClient() { forClient.Init("0.0.0.0", NetConfig.LISTENER_PORT); var addr = NetTool.GetAddress("0.0.0.0", NetConfig.LISTENER_PORT); Logger.LogInfo("初始化网络监听(客户端) [{0}]".FormatStr(addr)); }
public override void Setup(string ip, int port) { base.Setup(ip, port); _socket = new WebSocketSharp.WebSocket(NetTool.GetAddress(ip, port) + "/default"); _socket.OnOpen += (a, b) => { base.OnConnected(); }; _socket.OnClose += (a, b) => { base.OnClosed(); }; _socket.OnMessage += (a, b) => { base.OnReceived(b.RawData); }; }
public void Login() { BMLoginRequest msg = new BMLoginRequest(); msg.ListenerAddress = NetTool.GetAddress(NetConfig.LISTENER_IP, NetConfig.LISTENER_PORT); SendMessage <BMLoginRequest, BMLoginReply>(msg, (reply) => { Logger.Log($"登录主服成功, 战场名: {reply.Name}"); }); }
public override void Setup(string ip, int port) { base.Setup(ip, port); _socket = new WebSocketSharp.WebSocket(NetTool.GetAddress(ip, port) + "/default"); _socket.Log.Level = WebSocketSharp.LogLevel.Error; // _socket.WaitTime = TimeSpan.FromSeconds(1); _socket.OnOpen += (a, b) => { base.OnConnected(); }; _socket.OnClose += (a, b) => { base.OnClosed(); }; _socket.OnMessage += (a, b) => { base.OnReceived(b.RawData); }; }
public override void Setup(string ip, int port) { base.Setup(ip, port); _server = new WebSocketSharp.Server.WebSocketServer(NetTool.GetAddress(ip, port)); _server.Log.Level = WebSocketSharp.LogLevel.Error; _server.AddWebSocketService(defaultServicePath, () => { WebSocketSession session = new WebSocketSession(SendAction); session.onConnected = () => { OnSessionConnected(session); }; session.onClosed = () => { OnSessionClosed(session); }; session.onReceived = (data) => { OnSessionReceived(session, data); }; return(session.behavior); }); }