Skip to content

Commit 98e286c

Browse files
committed
add tcp demo
1 parent 31c1c15 commit 98e286c

File tree

17 files changed

+513
-422
lines changed

17 files changed

+513
-422
lines changed

Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,25 @@ public class TCPSocket : Details
77
{
88
private WXTCPSocket _tcpSocket;
99

10+
// 数据
11+
private string _stringData1 = "String Data";
12+
private string _stringData2 = "123\n";
13+
14+
15+
private byte[] _bufferData1 = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 };
16+
private byte[] _bufferData2 = { 0xab, 0x05, 0xd7, 0x05 };
17+
private byte[] _bufferData3 = new byte[8];
18+
19+
private int[] _bufferData4 = { 66, 117, 102, 102, 101, 114, 32, 68, 97, 116, 97, 32 };
20+
private int[] _bufferData5 = { 0xab, 0x05, 0xd7, 0x05 };
21+
private int[] _bufferData6 = new int[8];
22+
23+
1024
private void Start() {
1125
GameManager.Instance.detailsController.BindExtraButtonAction(0, connect);
1226
GameManager.Instance.detailsController.BindExtraButtonAction(1, close);
27+
GameManager.Instance.detailsController.BindExtraButtonAction(2, write);
28+
GameManager.Instance.detailsController.BindExtraButtonAction(3, writeBuffer);
1329
}
1430

1531
// 测试 API
@@ -18,6 +34,10 @@ protected override void TestAPI(string[] args)
1834
_tcpSocket = WX.CreateTCPSocket();
1935
Debug.Log("tcpSocket: " + JsonUtility.ToJson(_tcpSocket));
2036

37+
_tcpSocket.OnMessage((res) => {
38+
Debug.Log("onMessage: " + JsonUtility.ToJson(res));
39+
});
40+
2141
_tcpSocket.OnConnect((res) => {
2242
Debug.Log("onConnect: " + JsonUtility.ToJson(res));
2343
});
@@ -29,21 +49,40 @@ protected override void TestAPI(string[] args)
2949
_tcpSocket.OnClose((res) => {
3050
Debug.Log("onClose: " + JsonUtility.ToJson(res));
3151
});
32-
33-
_tcpSocket.OnMessage((res) => {
34-
Debug.Log("onMessage: " + JsonUtility.ToJson(res));
35-
});
3652
}
3753

3854
private void connect() {
55+
Debug.Log("connect test start");
3956
_tcpSocket.Connect(new TCPSocketConnectOption() {
40-
address = "192.168.193.2",
41-
port = 8848
57+
address = "www.oooceanworld.com", port = 8101
4258
});
4359
}
4460

4561
private void close() {
62+
Debug.Log("close test start");
4663
_tcpSocket.Close();
4764
}
65+
66+
private void write() {
67+
Debug.Log("write string test start: "+_stringData);
68+
_tcpSocket.Write(_stringData);
69+
}
70+
71+
private void writeBuffer()
72+
{
73+
Debug.Log("write buffer test start:");
74+
Debug.Log("test 1: "+_bufferData1);
75+
_tcpSocket.Write(_bufferData1);
76+
Debug.Log("test 2: " + _bufferData2);
77+
_tcpSocket.Write(_bufferData2);
78+
Debug.Log("test 3: " + _bufferData3);
79+
_tcpSocket.Write(_bufferData3);
80+
Debug.Log("test 4: " + _bufferData4);
81+
_tcpSocket.Write(_bufferData4);
82+
Debug.Log("test 5: " + _bufferData5);
83+
_tcpSocket.Write(_bufferData5);
84+
Debug.Log("test 6: " + _bufferData6);
85+
_tcpSocket.Write(_bufferData6);
86+
}
4887
}
4988

Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocketSO.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ MonoBehaviour:
2121
extraButtonList:
2222
- buttonText: "\u8FDE\u63A5"
2323
- buttonText: "\u5173\u95ED"
24+
- buttonText: "\u53D1\u9001String"
25+
- buttonText: "\u53D1\u9001Buffer"
2426
initialResultList: []

0 commit comments

Comments
 (0)