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");
        }
    }
Ejemplo n.º 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");
    }
Ejemplo n.º 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");
    }
Ejemplo n.º 4
0
    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");
    }