Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Gravn · Jul 30, 2012 at 08:09 PM · networkconnect

Network Connect to self after initializing server

Hi there, i´m currently making a multiplayer game, and i want the player to create a server and join that server immediately. As it is now, the player hosts a server, opens up another instance of the game and joins there.

Creating and joining is currently working.

//The player hosts a server after typing in the name of the server and Port he wants to use default port is 25600 if(creating = true)

{

     Network.InitializeServer(8,Connection_Port,false);

}

// The player starts an extra game instance and joins, after typing in the IP and Port to connect to. Default is IP: 127.0.0.1, Port: 25600. if (Joining = true)

{

    Network.Connect(Connect_To_Ip,Connection_Port);

}

But this does not work:

//The player Creates a server after choosing Servername and Portnumber. if(creating = true)

{

     Network.InitializeServer(8,Connection_Port,false);
     Network.Connect("127.0.0.1",Connection_Port);

}

ive got "Network.connections.Length" to show and is only counting 1 if i join with another instance. No errors occurs.

Getting this error: "The connection request to 127.0.0.1:26500 failed. Are you sure the server can be connected to?"

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

3 Replies

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

Answer by whydoidoit · Jul 30, 2012 at 08:26 PM

The player hosting the server is already connected to that server. You cannot connect to another game while you are a server so your second Network.Connect will either fail or shut down the server.

Comment
Add comment · Show 2 · 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 Gravn · Jul 30, 2012 at 10:09 PM 0
Share

wait. so the hosting player is actually able to play with the connecting players then?

avatar image whydoidoit · Jul 30, 2012 at 11:39 PM 0
Share

Yep :) No problem...

avatar image
1

Answer by Gravn · Jul 30, 2012 at 10:30 PM

Now i get it. The host can play on the server himself, i just never let him, i just showed him a host admin page instead of the playing field :)

Comment
Add comment · Show 1 · 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 Bunny83 · Jul 30, 2012 at 11:55 PM 0
Share

Exactly, that's how you can create a dedicated server ;)

Furthermore if you use a $$anonymous$$asterServer, take a look at the dedicatedServer property. This will only affect the playercount that is reported by the masterserver. If dedicatedServer is set to true, the server will not be count as player. The default is false, so the server is considered to be a player as well.

The documentation has a typing mistake in the description. The "false" in the last sentense should be "true" ;) The example is correct.

avatar image
0

Answer by Gravn · Jul 30, 2012 at 08:25 PM

i just found this after some more searching: http://answers.unity3d.com/questions/141976/ports-and-networking-problem.html

Bunny83: "You can never connect to yourself with Unity's network system because you can only be server OR client. The only way is to start your game two times and let one be the server and the other a client..."

Comment
Add comment · Show 2 · 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 whydoidoit · Jul 30, 2012 at 08:26 PM 0
Share

:) Snap!!!!

avatar image whydoidoit · Jul 30, 2012 at 08:29 PM 0
Share

$$anonymous$$y game has players being the server all the time though. It just takes some fiddling with the instantiations and messages.

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

8 People are following this question.

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

Related Questions

connect with Server(Host) 0 Answers

Network.Connect() won't connect? 0 Answers

How do you connect two existing networkviews? 1 Answer

Unhandled message 65 from local ip. 0 Answers

How to set up 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