0

On my unity client app when I try to connect to my local web server (Tomcat 7) who is running on the address 127.0.0.1:8080 I get the error "The connection request to 127.0.0.1:8080 failed[...]". Here is a snippet of my code:

public class Game: MonoBehaviour {
public GameObject board;
public GameObject player;

 void Awake () { (...) Network.Connect("localhost", 8080); } //other methods... 

}

I'm using Unity 4.3.2.

What am I missing here?

Cheers

1
  • Woah, buddy! UnityEngine.Network is not an HTTP library. The simplest alternative is to use Unity3D's WWW class, as it plays nicely with coroutines and other Unity internals. I've seen other attempts to build HTTP clients that work with Unity, but not yet one that I'd recommend for general use. Commented Jan 9, 2014 at 21:41

1 Answer 1

0

First off, check if it is indeed running. netstat command would give you that. Next, check if you can access tomcat from the browser like any other web page. Third, and if first two are yes, then try this: Tomcat is running on 127.0.0.1 and you're trying to access with localhost. See if you have your hosts mapped. Ideally they should, but check if localhost is mapped to 127.0.0.1 (etc/hosts) file. Or try 127.0.0.1 in your code and post any exceptions in Tomcat logs. See if you request comes into Tomcat in the first place.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your anwser! Yes, I did all that and I confirmed that my server was running but still I get that error. The Network class uses Unity's own networking/RPC protocol built on top of UDP. So I must use WWW class but on the specs it says that it can only be used to send GET and POST resquests, but I also need to send PUT and DELETE requests... (my game server is a restful webservice)
So it looks more of a framework issue than Tomcat's. :)