public void Awake(NetworkProtocol protocol) { try { switch (protocol) { case NetworkProtocol.KCP: this.Service = new KService() { Parent = this }; break; case NetworkProtocol.TCP: this.Service = new TService() { Parent = this }; break; case NetworkProtocol.WebSocket: this.Service = new WService() { Parent = this }; break; } } catch (Exception e) { throw new Exception($"{e}"); } }
public void Awake(NetworkProtocol protocol, IPEndPoint ipEndPoint) { try { switch (protocol) { case NetworkProtocol.TCP: this.Service = new TService(ipEndPoint); break; case NetworkProtocol.KCP: this.Service = new KService(ipEndPoint); break; default: throw new ArgumentOutOfRangeException(); } this.StartAccept(); } catch (Exception e) { throw new Exception($"{ipEndPoint}", e); } }
public void Awake(NetworkProtocol protocol, int packetSize = Packet.PacketSizeLength2) { switch (protocol) { case NetworkProtocol.KCP: this.Service = new KService() { Parent = this }; break; case NetworkProtocol.TCP: this.Service = new TService(packetSize) { Parent = this }; break; case NetworkProtocol.WebSocket: this.Service = new WService() { Parent = this }; break; } }
public void Awake(NetworkProtocol protocol) { try { switch (protocol) { case NetworkProtocol.KCP: this.Service = new KService(); break; case NetworkProtocol.TCP: this.Service = new TService(); break; default: throw new ArgumentOutOfRangeException(); } this.Service.AcceptCallback += this.OnAccept; this.Start(); } catch (Exception e) { throw new Exception($"{e}"); } }
/// <summary> /// 初始化 /// </summary> /// <param name="protocol">通讯协议 TCP ? KCP ? WEB?</param> /// <param name="address">本地IP地址</param> public void Awake(NetworkProtocol protocol, string address) { try { IPEndPoint ipEndPoint; switch (protocol) { case NetworkProtocol.KCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new KService(ipEndPoint, this.OnAccept); //传过去 得到客户端AChannel的回调 break; case NetworkProtocol.TCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new TService(ipEndPoint, this.OnAccept); break; case NetworkProtocol.WebSocket: string[] prefixs = address.Split(';'); this.Service = new WService(prefixs, this.OnAccept); break; } } catch (Exception e) { throw new Exception($"NetworkComponent Awake Error {address}", e); } }
public WChannel(WebSocket webSocket, AService service) : base(service, ChannelType.Connect) { this.InstanceId = IdGenerater.GenerateId(); this.webSocket = webSocket; this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); }
protected AChannel(AService service, ChannelType channelType) { //生成ID this.Id = IdGenerater.GenerateId(); //接受连接 或者 进行连接 this.ChannelType = channelType; //网络服务 this.Service = service; }
public WChannel(WebSocket webSocket, AService service) : base(service, ChannelType.Connect) { this.webSocket = webSocket; this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.recvStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.isConnected = false; }
public WChannel(HttpListenerWebSocketContext webSocketContext, AService service) : base(service, ChannelType.Accept) { this.WebSocketContext = webSocketContext; this.webSocket = webSocketContext.WebSocket; this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); this.recvStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue); isConnected = true; }
protected override void OnDestroy() { foreach (Session session in this.sessions.Values.ToArray()) { session.Dispose(); } this.Service?.Dispose(); this.Service = null; }
public void Awake(NetworkProtocol protocol) { switch (protocol) { case NetworkProtocol.TCP: this.Service = new TService() { Parent = this }; break; } }
public void Awake(NetworkProtocol protocol) { switch (protocol) { case NetworkProtocol.TCP: this.Service = new TService(); break; case NetworkProtocol.KCP: this.Service = new KService(); break; default: throw new ArgumentOutOfRangeException(); } }
public void Awake(NetworkProtocol protocol, string address) { try { IPEndPoint ipEndPoint; switch (protocol) { case NetworkProtocol.TCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new TService(ipEndPoint, this.OnAccept) { Parent = this }; break; } } catch (Exception e) { throw new Exception($"NetworkComponent Awake Error {address}", e); } }
public void Awake(NetworkProtocol protocol, string address, int packetSize = Packet.PacketSizeLength2) { try { IPEndPoint ipEndPoint; switch (protocol) { case NetworkProtocol.KCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new KService(ipEndPoint, this.OnAccept) { Parent = this }; break; case NetworkProtocol.TCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); //OnAccept客户端连接后的处理回调 同时将自己设置为TService的Parent父物体 //那么这个外网组件销毁的时候 会将TService也销毁 this.Service = new TService(packetSize, ipEndPoint, this.OnAccept) { Parent = this }; break; case NetworkProtocol.WebSocket: string[] prefixs = address.Split(';'); this.Service = new WService(prefixs, this.OnAccept) { Parent = this }; break; } } catch (Exception e) { throw new Exception($"NetworkComponent Awake Error {address}", e); } }
public void Awake(NetworkProtocol protocol, string address, int packetSize = Packet.PacketSizeLength4) { try { IPEndPoint ipEndPoint; switch (protocol) { case NetworkProtocol.KCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new KService(ipEndPoint, (channel) => { this.OnAccept(channel); }) { Parent = this }; break; case NetworkProtocol.TCP: ipEndPoint = NetworkHelper.ToIPEndPoint(address); this.Service = new TService(packetSize, ipEndPoint, (channel) => { this.OnAccept(channel); }) { Parent = this }; break; case NetworkProtocol.WebSocket: string[] prefixs = address.Split(';'); this.Service = new WService(prefixs, (channel) => { this.OnAccept(channel); }) { Parent = this }; break; } } catch (Exception e) { throw new Exception($"NetworkComponent Awake Error {address}", e); } }
protected AChannel(AService service, ChannelType channelType) { this.Id = IdGenerater.GenerateId(); this.ChannelType = channelType; this.service = service; }
public override void Awake(JToken jd = null) { if (jd == null) { return; } if (jd.Parent != null && jd.Parent.Parent != null && jd.Parent.Parent["appType"] != null) { string[] array = jd.Parent.Parent["appType"].ToString().Replace(" ", "").Split('|'); for (int i = 0; i < array.Length; i++) { if (array[i] != "") { appType |= (int)Enum.Parse(typeof(AppType), array[i]); } } } protocol = NetworkProtocol.TCP; if (jd["protocol"] != null) { Enum.TryParse <NetworkProtocol>(jd["protocol"].ToString(), out protocol); } address = jd["address"]?.ToString(); if (address != null && address != "" && protocol != NetworkProtocol.HttpSocket) { ipEndPoint = NetworkHelper.ToIPEndPoint(address); } else { ipEndPoint = new IPEndPoint(IPAddress.Any, 0); } if (jd["MessagePacker"]?.ToString() == "ProtobufPacker") { MessagePacker = new ProtobufPacker(); } else { MessagePacker = new MongoPacker(); } try { switch (protocol) { case NetworkProtocol.KCP: this.Service = new KService(ipEndPoint, this.OnAccept); break; case NetworkProtocol.TCP: this.Service = new TService(ipEndPoint, this.OnAccept); break; case NetworkProtocol.WebSocket: this.Service = new WService(address.Split(';'), this.OnAccept); break; case NetworkProtocol.HttpSocket: string[] prefixs = address.Split(';'); Boolean.TryParse(jd["website"]?.ToString(), out bool website); this.Service = new HttpService(prefixs[0], website, this.OnAccept); break; } } catch (Exception e) { Log.Debug($"创建KService失败!{e.Message}"); //throw new Exception($"NetworkComponent Awake Error {address}", e); } ipEndPoint = this.Service.GetEndPoint(); IdGenerater.AppId = ipEndPoint.Port; if (jd["CheckHearBeat"] != null && this.Service != null) { this.Service.CheckHearBeat = jd["CheckHearBeat"].ToObject <bool>(); } if (jd["CheckKcpWaitsnd"] != null && this.Service != null) { this.Service.CheckKcpWaitsnd = jd["CheckKcpWaitsnd"].ToObject <bool>(); } }
protected AChannel(AService service, ChannelType channelType) { this.ChannelType = channelType; this.service = service; }