Skip to content

Commit

Permalink
解决kcp链接失效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TastSong committed Feb 12, 2023
1 parent a813217 commit 17b0c8c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CrazyCarClient/Assets/Plugins/KcpCSharp/KcpOnUdp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Text;
using System.Net.Sockets;
using System.Net;
using UnityEngine;
using Object = System.Object;

namespace KcpCSharp {
public abstract class KcpOnUdp : Output {
Expand Down
4 changes: 2 additions & 2 deletions CrazyCarClient/Assets/Scripts/System/KCPSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void CloseConnect() {
}

public void Connect(string url, int port) {
host = Util.GetServerHost(this.GetSystem<INetworkSystem>().ServerType);
host = Util.GetServerHostIP(this.GetSystem<INetworkSystem>().ServerType);
this.port = port;
this.url = url;
kcpManager.ConnectKCP(host, port, url);
Expand Down Expand Up @@ -79,7 +79,7 @@ public void ConnectKCP(string host, int port, string url) {
if (client != null && client.IsRunning()) {
return;
}
Debug.LogError("host " + host + " port " + port + " url " + url);
Debug.Log("host " + host + " port " + port + " url " + url);
CoroutineController.manager.StartCoroutine(this.GetSystem<INetworkSystem>().POSTHTTP(
url: this.GetSystem<INetworkSystem>().HttpBaseUrl + url,
token: this.GetModel<IGameModel>().Token.Value,
Expand Down
17 changes: 14 additions & 3 deletions CrazyCarClient/Assets/Scripts/Utility/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ public static string GetServerBaseUrl(ServerType serverType) {
public static string GetServerHost(ServerType serverType) {
switch (serverType) {
case ServerType.Local:
return "127.0.0.1";
return "localhost";
case ServerType.Remote:
//return "139.9.103.145";
return "tastsong.xyz";
case ServerType.TestServer:
//return "101.34.205.139";
return "tastsong.top";
default:
return "localhost";
}
}

public static string GetServerHostIP(ServerType serverType) {
switch (serverType) {
case ServerType.Local:
return "127.0.0.1";
case ServerType.Remote:
return "139.9.103.145";
case ServerType.TestServer:
return "101.34.205.139";
default:
return "127.0.0.1";
}
Expand Down

0 comments on commit 17b0c8c

Please sign in to comment.