Search Unity

WebGL Networking help!

Discussion in 'Web' started by aodonn, Sep 12, 2019.

  1. aodonn

    aodonn

    Joined:
    Aug 20, 2015
    Posts:
    6
    Hi there, I'm wondering how I can get connections using direct socket access to work with a webGL build. Below is the code I'm trying to translate:

    Code (CSharp):
    1. private TcpClient twitchClient;
    2. private StreamReader reader;
    3. private StreamWriter writer;
    4.  
    5.     public void Connect()
    6.     {
    7.         twitchClient = new TcpClient("irc.chat.twitch.tv", 6667);
    8.  
    9.         reader = new StreamReader(twitchClient.GetStream());
    10.         writer = new StreamWriter(twitchClient.GetStream());
    11.  
    12.         writer.WriteLine("PASS " + password);
    13.         writer.WriteLine("NICK " + username);
    14.         writer.WriteLine("USER " + username + " 8 * :" + username);
    15.         writer.WriteLine("JOIN #" + channelName);
    16.         writer.Flush();
    17.     }
    18.  
    Since this method is not available for webGL builds I'm wondering how easy this is to convert to WWW or UnityWebRequest.

    I'm really not very experienced this this side of things so excuse me if I seem like I don't have a clue what I'm talking about (as I really don't!).

    I appreciate all and any help, thanks!
     
  2. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    71
    Did you ever get a solution for this Aodonn?
     
  3. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    Since there is no raw TCP Socket API in JavaScript (and WebAssembly) on the browser, there is no choice but to use WebSocket or HTTP protocol. (There is a new API called Web Transport (QUIC), but it is too new)
     
  4. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    71
    Thanks gtk2k - I was hoping someone might have already developed some replacement code for the basic TCPClient calls, using WebSocket :)