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 /
  • Help Room /
avatar image
2
Question by IgnitedGames · Mar 16, 2020 at 05:03 AM · networkingmultiplayertransport

AnyIpv4 and LoopbackIpv4

I'm creating a pretty jank multiplayer solution for my game that uses unity's transport system. To keep it short, there is absolutely no explanation anywhere as to what the hell NetworkEndPoint.AnyIpv4 and NetworkEndPoint.LoopbackIpv4 are. I'm basically trying to make it so you can join someone's game by typing in their IP Address and Port, and Host the game by using your IPv4 Address and selecting a port. I am using Unity's jobified client and server scripts in the documentation, but it doesn't say why it chooses to use loopbackipv4 and anyipv4, nor what they do. Can I use NetworkEndPoint.Parse()? I tried using it, but it didn't work. Any help is greatly appreciated.

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

2 Replies

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

Answer by Gavor · May 05, 2020 at 12:27 AM

For what it's worth, I had the same problem today and am coming from a position of only having a high level understanding of networking and almost no Unity networking experience. Below is my solution.

Basically I convert my string IP into an IPAddress object using Parse and then I convert that into a NativeArray of byte data. The endpoint object is set to AnyIpv4 and I use SetRawAddressBytes(), sending it the NativeArray.

This may not be the best or only solution, this is just what I used today.

     m_Driver = NetworkDriver.Create();
     m_Connection = default(NetworkConnection);

     // Basically I convert my string IP into an IPAddress object using Parse
     IPAddress serverAddress = IPAddress.Parse(GameObject.Find("IP").GetComponent<InputField>().text);
     NativeArray<byte> nativeArrayAddress;

     // Convert that into a NativeArray of byte data
     nativeArrayAddress = new NativeArray<byte>(serverAddress.GetAddressBytes().Length, Allocator.Temp);

     nativeArrayAddress.CopyFrom(serverAddress.GetAddressBytes());

     // Set to AnyIpv4
     NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4;
     endpoint.SetRawAddressBytes(nativeArrayAddress);         // Use SetRawAddressBytes
     endpoint.Port = 9000;
     
     // Then call the Connect method on your driver.
     m_Connection = m_Driver.Connect(endpoint);
Comment
Add comment · Show 7 · 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
avatar image IgnitedGames · May 07, 2020 at 01:43 AM 1
Share

Thank you so much for the answer! I really appreciate it. Question: Why is the port always set to 9000? Should I allow the player to alter it? And also this should allow people on different networks to play, right? Also what is addressData and where does it come from, is address data just nativeArrayAddress?

avatar image Gavor · May 07, 2020 at 11:11 PM 1
Share

The port doesn't have to be 9000, in a later version of this code I use a value entered into an inputfield by the user. It does have to be an unused port though. I have tested this with friends and it works 100%. $$anonymous$$ake sure the port uses is forwarded on the router (depends on your network and internet, but 99% of the time you'll need to forward the port).

Apologies, I put this code together from two different sources and didn't proof read it well enough it seems. addressData is nativeArrayAddress. I'll amend the original answer.

avatar image IgnitedGames Gavor · May 08, 2020 at 12:01 AM 0
Share

Edit 4: Previous problem isn't a problem anymore, I got it working! A problem though is that my console is being spammed with:

Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 5)

no idea why this is happening, pretty sure it's because I'm not releasing something or rather, but if that means I need to close and open the connection every time I want to send data then that's a bit annoying. Basically, with this I'm just trying to have the world's most basic multiplayer where the transform.position of the players is just sent to the host and then to the other players, but idk how to stream data without doing something dumb and unoptimized like having the connection open and close unnecessarily every time data is sent. I really appreciate your help up until this point :), not sure if background in networking experience would be able to help

Here's what I said originally

avatar image vs743 IgnitedGames · May 13, 2020 at 10:01 AM 1
Share

usually that problem is called if the allocator is using Allocator.Temp or Allocator.TempJob and the NativeArray has not be disposed by the 4th frame. ideally, it should be disposed off at the end of the same function when the job is completed. Hope this helps

Show more comments
avatar image
0

Answer by IgnitedGames · Mar 17, 2020 at 04:35 AM

Another unanswered question there, but the answer to this question is here.

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

313 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 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 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

What is the most efficient way to host multiple games on different ports? 1 Answer

Multiplayer Camera Rotation On Client 0 Answers

UNET match making without the relay server 3 Answers

Android multiplayer using WiFi 5 Answers

Unity Networking 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