Exemple #1
0
 private void connectWebsocket(WebSocketUnity websocket)
 {
     webSocket = new WebSocketUnity("ws://" + address, this);          // <= local server
     // Second Step : we open the connection
     webSocket.Open();
     Debug.Log("Connected to " + address);
 }
    /// <summary>
    /// This function is called when the object becomes enabled and active.
    /// </summary>
    public void OnEnable()
    {
        // Create web socket
        webSocket = new WebSocketUnity("ws://172.18.138.247:9999", this);

        // Open the connection
        webSocket.Open();
    }
Exemple #3
0
    IEnumerator sleepStart()
    {
        print(Time.time);
        yield return(new WaitForSeconds(5));

        print(Time.time);
        webSocket = new WebSocketUnity("wss://staging.projectamelia.ai/pusherman/companions/login/websocket?app=ublob", this); // <= public server
        webSocket.Open();
        Debug.Log("closed!!");
    }
Exemple #4
0
    /// <summary>
    /// This function is called when the object becomes enabled and active.
    /// </summary>
    public void OnEnable()
    {
        // Create web socket
        Debug.Log("Connecting" + websocketServer);
        string url = "ws://" + websocketServer + ":" + websocketPort;

        webSocket = new WebSocketUnity(url, this);

        // Open the connection
        webSocket.Open();
    }
    void OnGUI()
    {
        // Make a background box
        GUI.Box(new Rect(10, 10, 400, 400), "Actions");

        // Check if the websocket has an opened connection
        if (webSocket == null || !webSocket.IsOpened())
        {
            // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
            if (GUI.Button(new Rect(30, 40, 320, 80), "Connect"))
            {
                // Warning : some libraries (for example on ios) don't support reconnection
                //         so you need to create a new websocketunity before each connect (destroy your object when receive a disconnect or an error)
                webSocket = new WebSocketUnity("ws://127.0.0.1:5566", this);                 // <= public server
                //webSocket = new WebSocketUnity("ws://localhost:8080", this); // <= local server

                // Second Step : we open the connection
                webSocket.Open();
            }
        }
        else
        {
            // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
            if (GUI.Button(new Rect(30, 40, 320, 80), "Disconnect"))
            {
                // Third Step : we need to close the connection when we finish
                webSocket.Close();
            }

            if (GUI.Button(new Rect(30, 130, 320, 80), "Send message data"))
            {
                // create or modify json object
                JsonData newFriend = new JsonData();
                newFriend["Hello"]         = new JsonData();
                newFriend["Hello"]["Name"] = "terry";
                string strFriends = newFriend.ToJson();
                Debug.Log(strFriends);

                webSocket.Send(strFriends);
                sendingMessage = true;
            }

            if (sendingMessage)
            {
                GUI.Label(new Rect(30, 350, 400, 60), "Waiting answer from server...");
            }
            else if (receivedMessage)
            {
                GUI.Label(new Rect(30, 350, 400, 60), "Server sent an echo answer !");
            }
        }
    }
Exemple #6
0
    void Start()
    {
        nameGO = GameObject.FindWithTag("Player");
        name   = nameGO.GetComponent <Text>();

        url    = "https://scontent.cdninstagram.com/vp/40eca769e5c52d4d93f81d005e6f312f/5DCAF45F/t51.2885-19/s150x150/53745151_2080173922098515_549575747384115200_n.jpg?_nc_ht=scontent.cdninstagram.com";
        oldUrl = "https://scontent.cdninstagram.com/vp/40eca769e5c52d4d93f81d005e6f312f/5DCAF45F/t51.2885-19/s150x150/53745151_2080173922098515_549575747384115200_n.jpg?_nc_ht=scontent.cdninstagram.com";
        //StartCoroutine(getPic());
        webSocket = new WebSocketUnity("wss://staging.projectamelia.ai/pusherman/companions/login/websocket?app=ublob", this); // <= public server
        webSocket.Open();
        //callGetPic();
//      var factory = new WebSocketClientFactory();
// WebSocket webSocket = new WebSocket("wss://staging.projectamelia.ai/pusherman/companions/websocket?app=ublob"); //await factory.ConnectAsync(new System.Uri("wss://staging.projectamelia.ai/pusherman/companions/websocket?app=ublob"));
//      webSocket.onMessage += (sender, e) =>
//             Console.WriteLine ("Laputa says: " + e.Data);
//     webSocket.Connect();
    }
Exemple #7
0
    /// <summary>
    /// This function is called when the object becomes enabled and active.
    /// </summary>
    public void OnEnable()
    {
        if (DummyDataReplay)
        {
            return;
        }
        // Create web socket
        Debug.Log("Connecting" + websocketServer);
        string url = "ws://" + websocketServer + ":" + websocketPort;

#if UNITY_IOS && !UNITY_EDITOR
        Jetfire.Open(url);
#else
        if (DummyDataReplay)
        {
            return;
        }
        webSocket = new WebSocketUnity(url, this);
        // Open the connection
        webSocket.Open();
#endif
    }
 public void setOnlineMode(int online)
 {
     if (online == 1)
     {
         try {
             Debug.Log("Connecting to " + socketURL);
             webSocket = new WebSocketUnity(socketURL, this);
             webSocket.Open();
             offline        = false;
             txtStatus.text = "Online";
         }
         catch {
             offline        = true;
             txtStatus.text = "Offline";
             Debug.Log("In Offline mode");
         }
     }
     else
     {
         offline        = true;
         txtStatus.text = "Offline";
     }
 }
Exemple #9
0
 public void Open(string url, string protocol = null)
 {
     webSocket = new WebSocketUnity(url, this);
     webSocket.Open();
 }
Exemple #10
0
    void OnGUI()
    {
        // Make a background box
        GUI.Box(new Rect(10, 10, 400, 400), "Actions");

        // Check if the websocket has an opened connection
        if (webSocket == null || !webSocket.IsOpened())
        {
            // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
            if (GUI.Button(new Rect(30, 40, 320, 80), "Connect"))
            {
                // first step : we need to create the WebSocket
                //      You can use a websocketURL (ws://XXXXXXX or wss:XXXXXXXX)
                //		You need to give a MonoBehaviour object who will receive events
                //		This object must extend WebSocketUnityDelegate interface
                //      For example : TestWebSocketController inherits of WebSocketUnityDelegate
                //		You can create your own websocket server
                //		for example : https://github.com/willryan/em-websocket
                // Warning : some libraries (for example on ios) don't support reconnection
                //         so you need to create a new websocketunity before each connect (destroy your object when receive a disconnect or an error)
                //webSocket = new WebSocketUnity("ws://echo.websocket.org", this); // <= public server
                webSocket = new WebSocketUnity("ws://" + address, this);                 // <= local server

                // Second Step : we open the connection
                webSocket.Open();
            }
        }
        else
        {
            // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
            if (GUI.Button(new Rect(30, 40, 320, 80), "Disconnect"))
            {
                // Third Step : we need to close the connection when we finish
                webSocket.Close();
            }

            if (GUI.Button(new Rect(30, 130, 320, 80), "Send message"))
            {
                // Fourth Step : we can send message
                //    In this sample, we are waiting a "echo" message from the server
                //    when we will receive this message, we will be able to change the display
                webSocket.Send("Hello World");
                sendingMessage = true;
            }
            if (GUI.Button(new Rect(30, 220, 320, 80), "Send data"))
            {
                // Fifth Step : we can send Data
                //    In this sample, we are waiting a "echo" message from the server
                //    when we will receive this message, we will be able to change the display
                // You need a server which manages bytes message

                int    test1 = 42;
                int    test2 = 33;
                byte[] data  = new byte[8];

                byte[] testB1 = System.BitConverter.GetBytes(test1);
                byte[] testB2 = System.BitConverter.GetBytes(test2);

                testB1.CopyTo(data, 0);
                testB2.CopyTo(data, 4);

                webSocket.Send(data);
                sendingMessage = true;
            }

            if (sendingMessage)
            {
                GUI.Label(new Rect(30, 350, 400, 60), "Waiting answer from server...");
            }
            else if (receivedMessage)
            {
                GUI.Label(new Rect(30, 350, 400, 60), "Server sent an echo answer !");
                DisplayMessage(_message);
            }
        }
    }