|
|
@@ -24,20 +24,47 @@ namespace ET
|
|
|
this.ChannelType = ChannelType.Connect;
|
|
|
this.Id = id;
|
|
|
|
|
|
- string wsStr = $"ws://{ipEndPoint}";
|
|
|
-
|
|
|
- Log.Debug($"wc address:{address}");
|
|
|
- if (LauncherConfig.isHttps)
|
|
|
+ string wsStr;
|
|
|
+ bool isHttps = LauncherConfig.isHttps;
|
|
|
+
|
|
|
+ // 检查address是否是URL格式
|
|
|
+ if (!string.IsNullOrEmpty(address) && (address.StartsWith("http://") || address.StartsWith("https://")))
|
|
|
+ {
|
|
|
+ // 如果是URL格式,转换为WebSocket协议
|
|
|
+ if (address.StartsWith("https://"))
|
|
|
+ {
|
|
|
+ wsStr = address.Replace("https://", "wss://");
|
|
|
+ isHttps = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wsStr = address.Replace("http://", "ws://");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ipEndPoint != null)
|
|
|
+ {
|
|
|
+ // 如果不是URL格式但有IPEndPoint,使用IP+端口方式
|
|
|
+ wsStr = $"ws://{ipEndPoint}";
|
|
|
+ }
|
|
|
+ else if (!string.IsNullOrEmpty(address))
|
|
|
{
|
|
|
- Uri uri = new Uri(address);
|
|
|
- string hostAndPath = uri.Host + uri.AbsolutePath;
|
|
|
- wsStr = $"wss://{hostAndPath}";
|
|
|
+ // 如果没有IPEndPoint但有address,直接使用address作为WebSocket地址
|
|
|
+ // 支持IP:端口格式
|
|
|
+ wsStr = address.StartsWith("ws://") || address.StartsWith("wss://") ? address : $"ws://{address}";
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 无法构造WebSocket地址
|
|
|
+ Log.Error($"WChannel: Invalid address and ipEndPoint are both null");
|
|
|
+ throw new ArgumentException("Invalid address and ipEndPoint are both null");
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.Debug($"wc address:{address}");
|
|
|
Log.Debug($"wc wsStr:{wsStr}");
|
|
|
|
|
|
WebSocket ws = new WebSocket(new Uri(wsStr));
|
|
|
|
|
|
- if (LauncherConfig.isHttps)
|
|
|
+ if (isHttps || ipEndPoint == null)
|
|
|
{
|
|
|
this.RemoteAddress = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
|
|
|
}
|