Search Unity

UNet LLAPI connect to domain

Discussion in 'UNet' started by Elfinnik159, Feb 23, 2017.

  1. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Hello.
    Please tell me whether you can connect to the domain, instead of the IP?
    example:
    ip = "mainDomain.com";
    m_ConnectionId = NetworkTransport.Connect(m_GenericHostId, ip, port, 0, out error);
    (not working)

    ip = "localhost";
    ...
    (not working)
     
    IgorAherne likes this.
  2. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Have you tried the following:
    System.Net.IPAddress[] iplist = System.Net.Dns.GetHostAddresses("domain");
    string ipAddress = iplist[0].ToString();
    That will get the first IP Address linked to the domain, just in case you have 1 or many IP's linked to it.
     
    Foreman_Dev likes this.
  3. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    I need to connect to the domain as soon as a domain has SSL. If I understand correctly, you can not connect over IP with SSL accounts. But LLAPI does not even connect on localhost. P.S. Strange. The array contains 2 IP, the two are not mine. Apparently, this is due to cloudflare

    I am trying to understand this myself.
    https://forum.unity3d.com/threads/unet-wss-https.440463/
    It seems to me, my problem is that the browser is trying to connect to the
    wss: //178.170.189.96: 3000 /
    but not to
    wss: // domainURL /
    Therefore, I try to connect to a domain
     
  4. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    What do you mean by the browser, if your using NetworkTransport.Connect(...) that's a UDP socket connection and not a web page request.
     
  5. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Actually, I need to connect by using WSS LLAPI. In the subject (see link above) wrote, how to change ws on wss. I went out error, I tried to find a solution. At one forum (for php) found a similar situation, it said that you need to connect to the domain, as SSL, which is needed for wss is only at the domain. On HLAPI, it seems, you can specify the domain name (or localhost) instead of IP. I'm trying to find how to do it in LLAPI. P.S. It is possible that I did not understand. P.P.S. In the subject of WSS did not respond, I try to understand himself.
     
  6. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    The thing is domain destructi********.ru points to the following IP Addresses:
    IPv4: 104.###.###.61
    IPv6: 2400:###:###:1::###:8b3d
    However those IP's do not point back to that domain.

    The only IP that points back to that domain is 178.###.###.96, so their must be some internal routing going on for it to work, unless I am missing something.

    Now I see that, what else are you trying to do?
    What does that WebGL app need to do?

    If its connecting to a non Unity Service like a Webpage and its over HTTPS then you "shouldn't" need to use that wss stuff.
    If your WebGL App needs to request a webpage like for example a PHP Page, cant you use UnityWebRequest or WWW.

    I have some UnityWebRequest code that can call a HTTPS page if need it.
     
    Last edited: Feb 23, 2017
  7. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Also if I am not mistaken UNet uses sockets and sockets don't work on WebGL, which is why I asked what you WebGL app needs to actually do.

    So for now, ignore what you want it to use and explain what it needs to do.
    Then we can work from that.
     
    Last edited: Feb 23, 2017
  8. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    In the subject https://forum.unity3d.com/threads/unet-wss-https.440463/ They explained how to replace ws wss. UNet sockets work in WebGL. But only for http pages. For https must be replaced ws on wss, as written there. I replaced according to the instructions and got the error. Trying to fix it himself, I found that it could be because of links to the IP instead of the domain.

    Therefore, all I need is to connect a string NetworkTransport.Connect (m_GenericHostId, ip, port, 0, out error); where IP = "domain name"! = "IP adress"

    However, perhaps it is meaningless or not help. I'm just trying to find options. And still I hope that I will answer in the WSS + HTTPS topic.
    HTTP / HTTPS page - site with WebGL application.
    Server UNET LLAPI - .exe application on the server. To it is necessary to apply the standard LLAPI requests.

    104.###.###.61 - cloudflare IP
     
  9. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Well I am still new to LLAPI, but I have been creating network app for years.

    I will start with the IP in question: 104.###.###.61 you cannot use that to access your site.
    When you try that IP you get the following message:

    You've requested an IP address that is part of the Cloudflare network. A valid Host header must be supplied to reach the desired website.

    However IP 178.###,###.96 reaches your site.

    So you have a Server written in Unity, is that server using NetworkTransport ?
    If so, then its using UDP and connects to a certain port.

    I have a question, why are you accessing your site via HTTPS?

    I understand what your saying about WebGL not liking HTTPS and the work around hack to get it working etc, I am just not sure why your wanting to access your WebGL app via HTTPS, what is wrong with running your WebGL application via HTTP?

    This is why its all confusing.

    NetworkTransport.Connect(...) requires an IP address, have you tried this IP 178.###,###.96?
     
  10. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Social networking works only via https (wss). The compound of IP by ws (page http) takes place without problems. However, making that offer to wss, the connection is not via IP with an error. WebSocket connection to 'wss: //178.###.###.##: 3000 /' failed: Error in connection establishment: net :: ERR_CONNECTION_CLOSED

    The compound of the http (ws) is blocked on the page https as an unreliable and throws an exception.

    Perhaps you advise replacement LLAPI (WebGL, HTTPS (wss), server - .exe application on the unity or c # (not node.js),all free (not photon solutions/gameSparks))?
     
    Last edited: Feb 23, 2017
  11. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    My understanding was that WebGL couldn't use sockets when the actual WebGL app is run from a HTTPS location.
    So this: https://destructivebattlegame.ru/ would have an issue, where as http://destructivebattlegame.ru/ would be fine.

    My understanding was that a WebGL application can only be a client application and not a server.

    Now if your trying to get your WebGL application to connect to say https://somedomain.com then sockets is not the route for you and you cannot use NetworkTransport which uses UDP.

    If you want your WebGL app from your site to connect to say https://somedomain.com you need to try UnityWebRequest

    I have never created a WebGL project before so I am unaware if there is any issues with this, but I know UnityWebRequest can call HTTPS pages.

    I have always wrote my own Network code in either C++ (many years ago) and .NET using C# and never in unity so most of this is also new to me, so I am learning as I am searching.

    But the reason I say this is due to HTTP and HTTPS are for POST and GET etc Web Requests and not UDP or TCP socket connections etc.

    TCP and UDP sockets use IP Addresses which is normally why you do a host lookup first to get its IP and connect to that, HTTP and HTTPS are never used.

    Maybe its me not fully understanding you and what exactly you are trying to do.

    Or are you trying to create a game that is run from say a Facebook page and that said page run the WebGL or have I miss understood you again?
     
    Last edited: Feb 23, 2017
  12. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    For example, facebook app opens = iFrame application on links https: / domain

    This app is a multiplayer, which communicates with the server. Server - this is not WebGL build, but the .exe application on the server.

    Alas, I only know c #.
    A write network only c # difficult due to the fact that the possibility of c # far above what gives unity.

    I need to be able to write server-side code on c # data exchange ~ 10KB / 0.1 sec. (RPS 10)


    It is clear, thank you.
    I will watch UnityWebRequest.


    But, apparently, UnityWebRequest not intended for multiplayer at real time. And server at php.
    Apparently, it is necessary to teach Node.js
     
    Last edited: Feb 23, 2017
  13. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Ah, I now understand now.
    Thats fine, nothing wrong with writing it in C#, I love C#, all my tools get done in C#.

    Ah, that is true, some turn based games can be fine, sadly a realtime games would overwelm a web server, as

    I found out when I crashed Apache on our server a few times last week.

    Ok, I think I get you know.

    So your WebGL is included via an iFrame from the Facebook site.
    You need that WebGL client app to connect to your server which is an executable.

    Is that correct?

    So I assume you are moving objects etc that need to be kept track on, if so then TCP or UDP Sockets will be needed.

    So I now see your issue.

    Where is that server executable located, is it located on the same server as the WebGL Client app?

    Also what port is the server using, you will also need to open that port up so remote connections can access it.

    Say for example, your server executable and WebGL client app are both located on your server and it was using say port 12345.

    Your server will have to have that port opened for both TCP an UDP on the servers firewall, if the port used is not open the WebGL client will not be able to connect to the server.

    Please note that the WebGL client is located on your server, but is run on your PC, so the WebGL is an external connection to your server.

    Also what address have you got set for the src="?????" in the iFrame ?
     
  14. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    link to IFrame https://destructivebattlegame.ru

    I do not know how to facebook, but I point destructivebattlegame.ru, and a social network adds https: //

    Website with WebGL build is located in the same place where the .exe application (server).

    On http://destructivebattlegame.ru
    is connected via port 7777 or 433 (cloudflare open port). Connecting with UNet LLAPI on http page runs perfectly.

    What kind of technology do I use for the UDP / TCP connection? I have been looking for free ways, but found only node.js. Others do not work or WebGL, or WebGL WSS (https). Or, you can use all the same UNet LLAPI?

    P.S.
    on destructivebattlegame.ru is not running WebGL build.

    Error on ws on https
    Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
    on wss (after hack) on http/https
    WebSocket connection to 'wss://178.170.189.96:3000 (and 443,and 7777, etc.)/' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED
     
    Last edited: Feb 24, 2017
  15. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Ah, that's what I was afraid of, I was wondering if Facebook hardcoded the https:// part.

    As for what UDP / TCP connection, well as far as I have found so far (still new to unity's networking) is that it only uses UDP sockets.
    Sadly like you have found out WebGL doesn't like sockets when run from a HTTPS location.

    I am wondering where your server exe is located, is it located at destructivebattlegame.ru ?
    If so you will need to open the port up on your server that your WebGL client is connecting to or else it will fail.

    Give me a few hours and I will see if I can create a WebGL app and a very basic UDP Server to see what is exactly happening.
     
  16. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    Ok, I just got the following when trying WebGL:
    WebSocket connection to 'ws://192.168.2.247:27030/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

    Now about to try that plugin hack way.

    Well that didn't work either:
    WebSocket connection to 'wss://192.168.2.247:27030/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

    And that was not even using Facebook and was using HTTP to access the actual WebGL.

    See this is why I liked Webplayer better than WebGL.

    Ok, I have absolutely no idea why its not working.
    I think this is a WebGL issue due to no UDP packets are even sent.

    So sorry that I couldn't help you resolve your issue, this has also put a spanner in the works for me due to I was going to export my game client to WebGL later on, but now due to al lthe issue I won't be doing that.
     
    Last edited: Feb 24, 2017
  17. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Well, thanks for trying.

    As far as I know, from free solutions only Node.js, which operates on the HTTPS protocol.

    Someday, perhaps, I will teach Node.js.
     
    Last edited: Feb 24, 2017
  18. TheUKDude

    TheUKDude

    Joined:
    Jul 27, 2013
    Posts:
    72
    No worries, I also needed to know if this would of worked, but sadly no :(

    If I ever do find out how to do it with WebGL I will come back here and let you know.