Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by martinasenovdev · Jul 13, 2017 at 05:25 PM · unity 5webglsocketsocketsalternative

Unity WebGL websocket LLAPI alternatives?

First of all I am deeply confused about HLAPI, LLAPI, and WebSocket support in Unity WebGL exports. HLAPI and LLAPI work over UDP, while WebSocket is TCP based and HLAPI and LLAPI claim to support it? Not sure how to feel about that.

I have an authoritative server written in Java. It accepts TCP connections. I had written the Unity client side with System.Net.Sockets. In the editor and for mobile exports it works fine, but when I tried to export for WebGL I saw it is not going to work.

Because I didn't want to make the server support two protocols (UDP and TCP), but unify it to use just TCP, I decided to keep what I've done so far in the client and use it for mobile exports, and write different logic to go with WebGL exports.

Unfortunately all UNET talks about is how to create client-side hosts and other client-side clients to connect with it, but it DOESN'T SAY A WORD how to use UNET to connect over WebSocket to authoritative server.

This is what I've tried and currently all it does is initiating a handshake:

 override protected void initializeInternal ()
 {
     NetworkTransport.Init();

     ConnectionConfig serverConfig = new ConnectionConfig ();
     serverConfig.MaxCombinedReliableMessageCount = 1;
     serverConfig.MaxCombinedReliableMessageSize = 1;
     serverConfig.SendDelay = 0;
     serverConfig.WebSocketReceiveBufferMaxSize = commandByteArraySize;
     channelId = serverConfig.AddChannel(QosType.ReliableSequenced);
     HostTopology topology = new HostTopology(serverConfig, 1);

     hostId = NetworkTransport.AddHost (topology, port);

     Connect ();
 }

 public void Connect() {
     byte error;
     connectionId = NetworkTransport.Connect(hostId, host, port, 0, out error);
     Debug.Log("Connect host: " + host + "; port: " + port + "; error: " + (NetworkError) error);
 }

 override protected void writeData(byte[] data) {
     byte error;
     NetworkTransport.Send(hostId, connectionId, channelId, data, data.Length, out error);
     Debug.Log("Send host: " + host + "; port: " + port + "; error: " + (NetworkError) error);
 }

I didn't want to AddHost(), but I had to, because otherwise it didn't seem to even try establish a connection to the authoritative server.

The server accepts the handshake over TCP (which I'm not sure why is that, the Unity WebGL export seems to do the handshake over TCP, while the standard says it should be done over HTTP), and responds with a proper handshake response.

When the game starts, writeData() is called, but that data doesn't get to the server for whatever reason. The debug messages in the console say the status is Ok. However no messages received in the server.

All this, the lack of proper documentation on the topic, docs about LLAPI, HLAPI and bottom line how to use those libraries to initiate WebSocket communication under Unity WebGL exports boils down to one question:

With Unity WebGL exports, what good alternative libraries are there to establish connection to authoritative server which supports TCP?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

136 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Twitch chat on WEBGL 0 Answers

Can we use Unitys LLAPI to establish a socket connect with a server? 1 Answer

WebGL build with SocketIO throws errors 1 Answer

WebGL: Scroll Camera 0 Answers

[WEBGL] PLAYER CONTINUES TO RUN AFTER WEBGL-CONTENT IS REMOVED FROM DOM 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges