Skip to content

Commit 6b6e211

Browse files
committed
修正tcp udp实例二次初始化问题
1 parent 767ebbb commit 6b6e211

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public class TCPSocket : Details
77
{
88
private WXTCPSocket _tcpSocket;
9+
910
private bool _connected = false;
1011

1112
// 数据
@@ -29,6 +30,7 @@ protected override void TestAPI(string[] args)
2930
if(_tcpSocket == null)
3031
{
3132
_tcpSocket = WX.CreateTCPSocket();
33+
3234
Debug.Log("tcpSocket: " + JsonUtility.ToJson(_tcpSocket));
3335

3436
_tcpSocket.OnMessage((res) => {
@@ -48,7 +50,7 @@ protected override void TestAPI(string[] args)
4850
});
4951
} else
5052
{
51-
Debug.Log("tcp实例已初始化");
53+
Debug.LogError("tcp实例已初始化");
5254
}
5355

5456
}
@@ -59,9 +61,10 @@ private void close()
5961
{
6062
_tcpSocket.Close();
6163
_connected = false;
64+
_tcpSocket = null;
6265
} else
6366
{
64-
Debug.Log("关闭失败:tcp实例未初始化或未连接");
67+
Debug.LogError("关闭失败:tcp实例未初始化或未连接");
6568
}
6669

6770
}
@@ -77,7 +80,7 @@ private void connect() {
7780
_connected = true;
7881
} else
7982
{
80-
Debug.Log("连接失败:tcp实例未初始化或已连接");
83+
Debug.LogError("连接失败:tcp实例未初始化或已连接");
8184
}
8285
}
8386

@@ -102,7 +105,7 @@ private void write() {
102105
}
103106
} else
104107
{
105-
Debug.Log("发送失败:tcp实例未初始化或未连接");
108+
Debug.LogError("发送失败:tcp实例未初始化或未连接");
106109
}
107110
}
108111
}

Diff for: Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocket.cs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private void close() {
125125
{
126126
_udpSocket.Close();
127127
_connected = false;
128+
_udpSocket = null;
128129
} else
129130
{
130131
Debug.LogError("关闭失败:udp实例未初始化或未连接");

0 commit comments

Comments
 (0)