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 hydrix · Jul 01, 2016 at 07:35 AM · c#networkingmultiplayermultiplayer networking

LLAPI Networking: NetworkConnection.TransportRecieve not being used

I'm trying to create my own network interface using the ability to override the virtual functions NetworkConnection.TransportSend and NetworkConnection.TransportRecieve (btw this is a typo in the API, it's spelled receive!), here's my code:

 void CreateNetworkClient(ConnectionId _connectionId) { 
         Debug.Log("creating new network client with connectionId " + _connectionId);
         DummyConnection newDummyConnection = new DummyConnection ();
         newDummyConnection.Initialize ( _connectionId.ToString (), 0,  _connectionId.id, new HostTopology(connectionConfig, 100)); //create a new dummy connection, which we'll assign to the high level API networkClient from its constructor
 
         networkClient = new NetworkClient(newDummyConnection);
         networkClient.SetNetworkConnectionClass<DummyConnection> (); //not sure how to use this, because it's supposed to apply this class to /new/ connections
         networkClient.connection.logNetworkMessages = true;
         Debug.Log ("networkClient class: " + networkClient.networkConnectionClass.Name); //shows DummyConnection
         Debug.Log ("networkClient connection Id: " + networkClient.connection.connectionId);
         networkManager.client = networkClient;
 
         ClientScene.Ready (networkClient.connection); //tell server we're ready to spawn
         if (!networkClient.connection.isConnected)
             Debug.LogError ("network client failed to connect");
         
 
     }
 

     public class DummyConnection : NetworkConnection {
     //override the sending function called every time a networkClient or networkServer wants to send data. 
     public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error) {
         Debug.Log ("using dummy connection to send data to " + connectionId);
         error = 0;
         if (channelId == Channels.DefaultReliable)
             SendData (bytes, (short)connectionId, true); 
         else if (channelId == Channels.DefaultUnreliable)
             SendData (bytes, (short)connectionId, false);
         else
             Debug.LogError ("error in DummyConnection: unknown channel! Try using default reliable or unreliable or adding support");
         
         
         return true; //probably not good. This might trick it into thinking there's no errors, ToDo: fix
     
     }

     //just a debug function
     public override void TransportRecieve(byte[] bytes, int numBytes, int channelId)
     {
         StringBuilder msg = new StringBuilder();
         for (int i = 0; i < numBytes; i++)
         {
             var s = String.Format("{0:X2}", bytes[i]);
             msg.Append(s);
             if (i > 50) break;
         }
         Debug.Log("TransportRecieve h:" + hostId + " con:" + connectionId + " bytes:" + numBytes + " " + msg);

         HandleBytes(bytes, numBytes, channelId);
     }

 }


Basically I'm trying to make the networkClient and Server have their NetworkConnection use this class DummyConnection, which forcefully sends the data through my own networking solution. This is sort of an experiment. I "abuse" the parameters in NetworkConnection.Initialize simply putting my own custom connectionId generated by my networking solution, since I'm not using the NetworkConnection for anything else but to feign an actual connection. I'm doing this because I want to still be able to use the high level API with functions such as [SyncVar] and [Command]. So I connect with my own networking solution then add a dummy connection, and I'm trying to get the networkClient and networkServer to use this DummyConnection, but neither side shows the debug log s that should appear from sending through the DummyConnection.

However, setting the connections to use NetworkConnection.logNetworkMessages does indeed indicate that the client is sending data, logging in the console the first message (ClientScene.Ready()).

So my question is, am I setting this up correctly? Because I can't get it to even log errors through the DummyConnection at all.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by hydrix · Jul 06, 2016 at 07:27 AM

It took DAYS to arrive to this solution and the poor documentation was almost entirely to blame: It doesn't actually use TransportSend() and TransportRecieve() to send and receive data all data to the application layer as the documentation implies, or at least most of it. It actually uses simply

Send() which I suspected after noticing that this function was also a virtual function within NetworkConnection. There was nothing wrong with the config at all-

adding a few more override functions within the DummyConnection- one for Send() SendUnreliable() and all the rest solved the problem, now when my code runs ClientScene.Ready() it successfully uses my custom override function!

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

How can I assign every connecting player to one of two teams, so that both teams are balanced? 2 Answers

NetworkMatch creating match not being found when doing ListMatches 0 Answers

UNET cannot connect android devices. 1 Answer

How to connect to hosted scene (Multiplayer) 2 Answers


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