forked from kaistseo/UnitySocketIO-WebSocketSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMain.cs
More file actions
49 lines (36 loc) · 1 KB
/
Copy pathCMain.cs
File metadata and controls
49 lines (36 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CMain : MonoBehaviour {
SocketIOClient.Client socket;
void Start () {
socket = new SocketIOClient.Client("http://127.0.0.1:80/");
socket.On("connect", (fn) => {
Debug.Log ("connect - socket");
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("msg", "what's up?");
socket.Emit("SEND", args);
});
socket.On("RECV", (data) => {
Debug.Log (data.Json.ToJsonString());
});
socket.Error += (sender, e) => {
Debug.Log ("socket Error: " + e.Message.ToString ());
};
socket.Connect();
}
void Update () {
}
void OnGUI () {
if (GUI.Button (new Rect (20, 70, 150, 30), "SEND")) {
Debug.Log ("Sending");
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("msg", "hello!");
socket.Emit("SEND", args);
}
if (GUI.Button (new Rect (20, 120, 150, 30), "Close Connection")) {
Debug.Log ("Closing");
socket.Close();
}
}
}