Search Unity

Can I connect Unity App with Node.js server?

Discussion in 'Multiplayer' started by 8Observer8, May 11, 2016.

  1. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
    Hello,

    Can I connect Unity App with Node.js server by heroku.com and openshift.com?

    I try to use Unity Socket.IO Asset: https://www.assetstore.unity3d.com/en/#!/content/21721

    When I install this asset I can to use "Socket IO Component (Script)"

    I see this field on "Socket IO Component (Script)"

    Url: ws://127.0.0.1:3000/socket.io/?EIO=4&transport=websocket

    I deployed my 'server' on heroku.com I have this address: https://unitychat.herokuapp.com/

    I converted this address to IP here: http://www.hcidata.info/host2ip.cgi

    I replaced the Url field in ""Socket IO Component (Script)"" to:

    ws://176.34.115.171:3000/socket.io/?EIO=4&transport=websocket

    But I cannot connect with heroku. Why?
     
  2. 2rusbekov

    2rusbekov

    Joined:
    Jul 12, 2013
    Posts:
    43
    Have you found solution? I got same problem.
     
  3. Optimus_Prime

    Optimus_Prime

    Joined:
    Apr 15, 2015
    Posts:
    34
  4. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
    Yes, but only for WebGL. I used only JS version of socke.io (not Unity Socket.io) and I called JS functions by ExternalCall from C# scripts. It is the same: http://socket.io/get-started/chat/

    Yes, I do. But I cannot connect two apps. Maybe do you know a tutorial about how to connect Unity Socket.io with heroku or openshift?
     
  5. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
    I think that SignalR is better for WebGL and WCF is better than Node.js for desktop because you can study only C#. But I don't know could I use WCF in Unity? UNet is better for coop games, but not for massive games.
     
    Last edited: Jul 27, 2016
  6. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
  7. chin13577

    chin13577

    Joined:
    May 8, 2017
    Posts:
    17
    Did you find the solution?
    now I stuck in it.
     
  8. chin13577

    chin13577

    Joined:
    May 8, 2017
    Posts:
    17
    Hey ! I found the way!!.

    if you run server in the localhost. the url should have " : port"
    example (port = 47960)

    ws://127.0.0.1:47960/socket.io/?EIO=4&transport=websocket

    **but if you have deployed to heroku
    the url must delete " : port"

    ws://your-project-name.herokuapp.com/socket.io/?EIO=4&transport=websocket

    it's work!
     
    dude439 and 8Observer8 like this.
  9. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
    Thank you very much! It is realy works!

    heroku logs --tail
    I can complete this tutorial :cool:
    Pluralsight - Unity Multiplayer Game Development with Node
    https://www.pluralsight.com/courses/unity-multiplayer-game-dev-node-2454
     
  10. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
  11. FernandoRCosta

    FernandoRCosta

    Joined:
    Aug 29, 2014
    Posts:
    5
  12. 8Observer8

    8Observer8

    Joined:
    Apr 29, 2015
    Posts:
    99
    Please, describe me a problem with details. Heroku is your server, because the client is placed on the Heroku server. You can get file from your server (where you client placed) without problems. The CORS problem can be on the client side only, only if you want to get a file, for example, an image from an alias server. I can describe a situation when this problem can occur. Sometimes I keep images on Dropbox. Dropbox allow to get direct links but with some little manipulations. It this case I can use images, audio files, 3D models on Sandboxes.

    I upload files on Dropbox. I can share files and get links like this: https://www.dropbox.com/s/xyzabt54s8lpixh/199.jpg?dl=0

    I edit links like this: https://dl.dropboxusercontent.com/s/xyzabt54s8lpixh/199.jpg

    Now it is a direct link. I want to get this image on another web client, for example, on my web client on another server. In this case I can write:

    Code (JavaScript):
    1. image.crossOrigin = "";
    Sandbox


    <!DOCTYPE html>
    <html>

    <head>
    <title>CrossOrigin</title>
    </head>

    <body>
    <script>
    var image = new Image();
    image.onload = function()
    {
    document.body.appendChild(image);
    }
    image.crossOrigin = "";
    image.src = "https://dl.dropboxusercontent.com/s/xyzabt54s8lpixh/199.jpg";
    </script>
    </body>

    </html>
     
  13. Tushar_kmphasis

    Tushar_kmphasis

    Joined:
    Oct 5, 2019
    Posts:
    7
    Had you find the solution of Connect socket.io over HTTPS? if you have solution of that please post answer.
     
  14. Jeells

    Jeells

    Joined:
    Aug 1, 2018
    Posts:
    1
    Hi how i can connect with render.com? i put the link as in heroku but not work for me.