Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (36 sloc)
1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } | |
| } | |