예제 #1
0
	IEnumerator Start () {
        var ws = new HTTP.WebSocket ();

        //This lets the websocket connection work asynchronously.
        StartCoroutine (ws.Dispatcher ());

        //Connect the websocket to the server.
        ws.Connect (url);

        //Wait for the connection to complete.
        yield return ws.Wait();

        //Always check for an exception here!
        if(ws.exception != null) {
            Debug.Log("An exception occured when connecting: " + ws.exception);
        }

        //Display connection status.
        Debug.Log("Connected? : " + ws.connected);

        //If websocket connected succesfully, we can send and receive messages.
        if(ws.connected) {
            //This specified that our OnStringReceived method will be called when a message is received.
            ws.OnTextMessageRecv += OnStringReceived;
            //This sends a message to the server.
            ws.Send ("Hello!");

            ws.Send ("Goodbye");
        }
	}
예제 #2
0
    void WebSocketExample ()
    {
        var ws = new HTTP.WebSocket ();
        StartCoroutine (ws.Dispatcher ());

        ws.Connect ("http://echo.websocket.org");
        
        ws.OnTextMessageRecv += (e) => {
            Debug.Log ("Reply came from server -> " + e);
        };

        ws.Send ("Hello");
        ws.Send ("Hello again!");
        ws.Send ("Goodbye");
    }
예제 #3
0
    IEnumerator Start()
    {
        yield return null;

        var ws = new HTTP.WebSocket();
        StartCoroutine(ws.Dispatcher());

        ws.Connect(" http://chernobyl.local:8888/");
        ws.OnTextMessageRecv += (e) => {
            Debug.Log("Reply came from server -> " + e);
        };
        ws.Send("Hello");

        ws.Send("Hello again!");

        ws.Send("Goodbye");
    }
    IEnumerator Start()
    {
        yield return null;

        var ws = new HTTP.WebSocket();
        StartCoroutine(ws.Dispatcher());

        Debug.LogError(ws);

        ws.Connect("http://echo.websocket.org");

        ws.OnTextMessageRecv += (e) => {
            Debug.LogError("Reply came from server -> " + e);
        };
        ws.Send("Hello");

        ws.Send("Hello again!");

        ws.Send("Goodbye");
    }
예제 #5
0
 IEnumerator Start()
 {
     yield return null;
     ws = new HTTP.WebSocket ();
     ws.OnTextMessageRecv += HandleTextMessage;
     var qs = string.Format ("?client={0}-uniweb&version={1}&protocol={2}", Application.platform, VERSION, PROTOCOL);
     var completeURL = url + pusherKey + qs;
     ws.Connect (completeURL);
     yield return ws.Wait();
     if (!ws.connected) {
         Debug.LogError ("Could not connect.");
     } else {
         while(!connectedToPusher) yield return null;
     }
 }
예제 #6
0
 IEnumerator _Connect()
 {
     connected = false;
     ws = new HTTP.WebSocket ();
     StartCoroutine (ws.Dispatcher ());
     ws.connectionTimeout = connectionTimeout;
     ws.OnConnect += HandleOnConnect;
     ws.OnDisconnect += HandleOnDisconnect;
     ws.OnTextMessageRecv += HandleOnTextMessageRecv;
     status = "Connecting";
     ws.Connect (url);
     status = "Waiting for connection";
     yield return ws.Wait ();
     if (ws.exception != null) {
         Debug.Log ("An exception occured when connecting: " + ws.exception);
         if (reconnectOnLostConnection) {
             status = "Reconnecting";
             Invoke ("Connect", 2);
             yield break;
         }
     }
     status = "Connected";
 }