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
1
Question by hailtonothing · Sep 19, 2014 at 05:28 AM · networkconnection

Can't connect to localhost server - connection request failed

Hey everyone. Hoping someone might have an answer for what seems like a pretty ridiculous problem. I think I've read every answer related to this in here about 10 times, trying to find a solution.

Basically, I can't connect to a server hosted on localhost, from localhost. i.e. I have a server and client both running on the same machine, and the client just errors "the connection request to 127.0.0.1:whateverport failed. Are you sure the server can be connected to.

I've watched about six different client/server tutorials on YT, and I can't see what I'm doing wrong. The only difference is that most tutes use the same application as client/server, whereas I have two separate applications.

I have tried:

  • -run in background on/off for client and server and server only.

  • -multiple different port numbers

  • -connecting via LAN IP instead of "localhost" or "127..."

  • -connecting via public IP

  • -creating rules in windows firewall

  • -turning off windows firewall

  • -initialisation NAT param set to false, true, and removed (though I get an obsolete warning about that last)

  • -running 32 and 64 bit versions of the server

  • Adding the connect code to be triggered by a keypress instead of in the Start()

I just don't know what else to do. The one thing I know I haven't tried is using Unity's Master Server, but I didn't want to do this - seems highly unnecessary.

So time for some code. Server:

 using UnityEngine;
 using System.Collections;
 
 public class RemNetwork : MonoBehaviour {
 
     public GUIText updateScreen;
 
 
     void Start() {
         updateScreen.text = updateScreen.text + "\nServer started. Initialising... \n\n";
         LaunchServer ();
     }
 
     void LaunchServer() {
         //Network.incomingPassword = "test";
         Network.InitializeServer(16, 25003);
     }
 
     void OnServerInitialized() {
         updateScreen.text = updateScreen.text + "Server Initialised \n\n";
     }
 
     public void OnGUI()
     {
         if (Network.peerType == NetworkPeerType.Server)
         {
             GUI.Label(new Rect(300,100,400,30), "Clients connected: " + Network.connections.Length ); 
         }
     }}





Client: (in here I connect in the Start() function)

 void Start () {
         Network.Connect ("localhost", 25003);
         if (Network.isClient) 
         {
             Debug.Log ("Connected");
         } 
         else 
         {
             Debug.Log ("Not connected");
         }
 
     }

The network.isclient bit doesn't really work since it gets called before the connection can be established, but regardless, I quickly get the connection request failed message.

The server "works" as far as I can tell. It starts, it initialises, it lists connections as 0.

So currently, at a loss. Knowing my luck it's just something stupid. In the meantime I guess I'll give up and try using a master server implementation, but again, I'd really like not to have to do this.

Thanks in advance for any help you can provide!

Comment
Add comment · Show 1
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 hailtonothing · Sep 19, 2014 at 08:47 AM 0
Share

I initially had a server password as per some tute I was looking at at the time I coded it. It didn't work then with a password, so I removed the auth for it, and the param from the client. :( I haven't tried forcing null simply because I'm just not using it any more.

3 Replies

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

Answer by hailtonothing · Sep 25, 2014 at 01:17 PM

Hi guys, sorry I haven't been able to get back to testing this out, but have solved the problem. Well, to be specific, I haven't, but the problem is in my PC, somewhere. I ran the client and server on my laptop and it worked first time. Still does not run on my desktop (frustrating).

So there's a config issue, or a conflict with something... who knows! The point is, the code was fine, I just need to find where/what on my PC is causing the problem. Or work permanently from my laptop. (ugh)

So anyway, thanks for your suggestions - I did toy with them first before deciding to try another machine. :)

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
avatar image
1

Answer by Illusory_Stone · Sep 19, 2014 at 06:17 AM

This may sound obvious, but have you forced both server- and client-side password entries to ""? I see an entry commented out on the svr side, but nothing on the clientside to indicate you've tried this...

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
avatar image
0

Answer by dmg0600 · Sep 19, 2014 at 08:33 AM

Connections are not instantly established. You should move the check for connection to other place, like to Update. I would also change "localhost" to "127.0.0.1" just to be sure.

To check the connection you can use the OnConnectedToServer and OnDisconnectedFromServer methods.

 private bool connected = false;
 
 void Start () {
     Network.Connect("127.0.0.1", 25003);
 }
 
 void OnConnectedToServer() {
     connected = true;
 }
 
 void OnDisconnectedFromServer() {
     connected = false;
 }
 
 void OnGUI() {
     GUI.Label(new Rect(300,100,400,30), "Connected: " + (connected == true));
 }

Hope this helps!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How connect client to server when ip is private ? 2 Answers

How to check iphone network connection 0 Answers

Trying to Connect a Remote Computer from a Different ISP 0 Answers

Unity Master Server Connect to own Server won't work 0 Answers

[UNET] Handle Client Disconnection 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