/// <summary> /// ws://127.0.0.1:8080 /// tcp://127.0.0.1:8080 /// udp://127.0.0.1:8080 /// </summary> /// <param name="url"></param> /// <param name="netEnDecode"></param> /// <param name="netRespEvent"></param> /// <returns></returns> public bool Connect(string url, NetEnDecode netEnDecode, NetRespEvent netRespEvent) { if (string.IsNullOrEmpty(url)) { //Odin.Log.Error("Url Is Null"); return(false); } if (netEnDecode == null) { //Odin.Log.Error("NetEnDecode Is Null"); return(false); } if (netRespEvent == null) { //Odin.Log.Error("NetRespEvent Is Null"); return(false); } if (NetRespEvent == null) { NetRespEvent += netRespEvent; } else { bool isAddEvent = false; foreach (var @delegate in NetRespEvent.GetInvocationList()) { if (@delegate.GetHashCode() == netRespEvent.GetHashCode()) { isAddEvent = true; break; } } if (!isAddEvent) { NetRespEvent += netRespEvent; } } if (string.IsNullOrEmpty(url)) { //Odin.Log.Error("url error"); return(false); } this._url = url; var idx = url.IndexOf("://"); string prefix = url.Substring(0, idx); switch (prefix.ToLower()) { case "tcp": _client = new CustomTcpClient(OnRespMsgEvent, netEnDecode); return(StartConnect(url)); case "udp": _client = new CustomUdpClient(OnRespMsgEvent, netEnDecode); return(StartConnect(url)); case "ws": _client = new WebSocketClient(OnRespMsgEvent, netEnDecode); _client.Connect(url, 0); return(true); default: //Odin.Log.Error("does not support protocol"); return(false); } }