public AChannel ConnectChannel(string host, int port) { AChannel channel = this.service.GetChannel(host, port); channel.ConnectAsync(); return(channel); }
private void UpdateChannel(AChannel channel) { if (channel.Id == 0) { return; } while (true) { byte[] messageBytes = channel.Recv(); if (messageBytes == null) { return; } if (messageBytes.Length < 6) { continue; } Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0); try { this.Run(opcode, messageBytes); } catch (Exception e) { Log.Error(e.ToString()); } } }
public bool IsChannelConnected(NetChannelType channelType) { AChannel channel = GetChannel(channelType); if (channel == null) { return(false); } return(true); }
public void RemoveChannel(long channelId) { AChannel channel = this.service?.GetChannel(channelId); if (channel == null) { return; } this.service.Remove(channelId); channel.Dispose(); }
public void Close(NetChannelType channelType) { AChannel channel = this.GetChannel(channelType); if (channel == null || channel.Id == 0) { return; } this.channels.Remove(channelType); channel.Dispose(); }
private void Send(object message, uint rpcId) { Opcode opcode = EnumHelper.FromString <Opcode>(message.GetType().Name); byte[] opcodeBytes = BitConverter.GetBytes((ushort)opcode); byte[] seqBytes = BitConverter.GetBytes(rpcId); byte[] messageBytes = MongoHelper.ToBson(message); NetChannelType channelType; if ((ushort)opcode > 7000 && (ushort)opcode < 8000) { channelType = NetChannelType.Login; } else if ((ushort)opcode > 0 && (ushort)opcode <= 1000) { channelType = NetChannelType.Battle; } else { channelType = NetChannelType.Gate; } AChannel channel = this.GetChannel(channelType); if (channel == null) { throw new GameException("game channel not found!"); } channel.Send(new List <byte[]> { opcodeBytes, seqBytes, messageBytes }); if (OpcodeHelper.IsNeedDebugLogMessage(opcode)) { Log.Debug(MongoHelper.ToJson(message)); } }
public AChannel GetChannel(long channelId) { AChannel channel = this.service?.GetChannel(channelId); return(channel); }
protected void OnError(AChannel channel, SocketError e) { this.errorCallback(channel, e); }
public void Connect(NetChannelType channelType, string host, int port) { AChannel channel = Share.Scene.GetComponent <NetworkComponent>().ConnectChannel(host, port); this.channels[channelType] = channel; }