View Full Version : [Solved] unity and electroserver tutorial one
jin76
01-31-2011, 05:44 PM
hello
I am a new user to Electoserver and I am having some difficulties with this tutorial:
http://www.youtube.com/watch?v=5OA3tPruXT4
when i hit the play button on unity, i do not get any debug statement, even though according to the code, i am supposed to be getting a statement stating "connection Sucess" true or false.
here is my code
using UnityEngine;
using System.Collections;
using Electrotank.Electroserver5.Api;
using Electrotank.Electroserver5.Core;
public class Main : MonoBehaviour {
ElectroServer es = new ElectroServer();
// Use this for initialization
void Start () {
es.Engine.Queueing = EsEngine.QueueDispatchType.External;
es.Engine.ConnectionResponse += OnConnectionResponse;
Server server = new Server("Server1");
AvailableConnection availCon = new AvailableConnection("127.0.0.1", 9899, AvailableConnection.TransportType.BinaryTCP);
server.AddAvailableConnection(availCon);
es.Engine.AddServer(server);
// Security.PrefetchSocketPolicy("192.168.1.5" ,9899);
es.Engine.Connect();
}
void OnConnectionResponse (ConnectionResponse e){
Debug.Log("Connection Sucess:" + e.Successful.ToString());
}
void OnApplicationQuit()
{
es.Engine.Close();
Debug.Log("es is closed");
}
// Update is called once per frame
void Update () {
es.Engine.Dispatch();
}
}
if anyone can help me find the error it will be helpfull
tcarr
01-31-2011, 05:53 PM
Which player are you targeting? If you are targeting the web player, then you need a prefetch line. With web player, if your ES5 is not running locally with port 9899, you won't get a connection response at all because it will be looking on the wrong port for the policy file.
jin76
01-31-2011, 05:56 PM
the line with the webplayer security (Security.PrefetchSocketPolicy("192.168.1.5" ,9899); is commented out
i am trying to do exactly what the video is doing
tcarr
01-31-2011, 06:02 PM
So what does your Unity build configuration say is the player that you are targeting? Are you testing from inside the editor or generating a build and then testing? I didn't create that video and don't have time to watch it right now.
jin76
01-31-2011, 06:04 PM
i am testing inside unity editor, and the console does not return anything.
i tested the whole code with debug statements, and the only lines that do not return the statement is
es.Engine.ConnectionResponse += OnConnectionResponse;
and
void OnConnectionResponse (ConnectionResponse e){
Debug.Log("Connection Sucess:" + e.Successful.ToString());
so something might b wrong with those
tcarr
01-31-2011, 06:11 PM
Please check File - Build Settings. Change to Standalone, debug build. Test again. If you still aren't seeing that debug line, please add debug lines before and after this one:
es.Engine.ConnectionResponse += OnConnectionResponse;
That's so I can tell whether the code snippet that adds the listener is being executed at all.
tcarr
01-31-2011, 06:12 PM
One more. Add this line to your script before you try to connect. This turns on the ES5 client debug lines.
log4net.Config.BasicConfigurator.Configure();
jin76
01-31-2011, 06:21 PM
i added the log lines, it is being executed but is not returning anything from the server
hmm i continued to the next tutorial where we get a login response from the server and it does not return anything either, i think something might be wrong with my server
jin76
01-31-2011, 06:24 PM
when i added the second line, it says :
Connection failed: No connection could be made because the target machine actively refused it.
UnityEngine.Debug:Log(Object)
log4net.ILog:Debug(String)
Electrotank.Electroserver5.Core.SyncSocketConnecti on:Connect()
Electrotank.Electroserver5.Core.EsEngineDefault:At temptConnection()
Electrotank.Electroserver5.Core.EsEngineDefault:Co nnect()
Main:Start() (at Assets/Main.cs:42)
tcarr
01-31-2011, 06:26 PM
This means that you don't have your ES5 set up correctly, or possibly you have a firewall in the way. Can you connect to your ES5 using our code examples, such as SimpleChat?
jin76
01-31-2011, 06:29 PM
when i try the chat example and try to connect it says
Connection failed: Unable to connect, as no valid crossdomain policy was found
UnityEngine.Debug:Log(Object)
log4net.ILog:Debug(String)
tcarr
01-31-2011, 06:33 PM
Log in to your ES5 admin, and look at the bottom of the General Settings screen. Are you using a custom policy file or not? With SimpleChat you should be able to connect if you are NOT using a custom policy file, as long as you are connecting locally. That is, if your ES5 is running from your desktop, and it has listeners on 0.0.0.0 and the client is running from your desktop and it is using 127.0.0.1 to connect to the same port.
If you are using a custom policy file, odds are there's a typo in it.
jin76
01-31-2011, 06:35 PM
both the policy options are checked off,
should i enable "enable policy file" ?
btw on my server notifications it says Failed opening a listener on: /0.0.0.0:10000
tcarr
01-31-2011, 06:37 PM
Yes, you need "enable policy file" checked on.
jin76
01-31-2011, 06:48 PM
it still did not work, i restarted the server as well
still get the error
Connection failed: Unable to connect, as no valid crossdomain policy was found
UnityEngine.Debug:Log(Object)
would it help if i upload an image of my policy?
tcarr
01-31-2011, 06:53 PM
First, try the Java version of SimpleChat. See if that connects correctly. You should be able to run it by simply double clicking code_examples/SimpleChat/client/java/bin/SimpleJavaChat.jar. Does that work? The next test is to run the AS3 version of SimpleChat. You may need to configure your Flash global security settings to allow sockets in that part of your hard drive. If you can get both of those to work, then we know that your ES5 is configured properly. I've had problems sometimes with connecting from inside the Unity Editor, but I can give some advice on how to do so, as long as we know your ES5 is set up right.
jin76
01-31-2011, 07:00 PM
when i try the java example,, it says room is null each time i try to send a message
"Initializing
loadAndConnect
Unable to send message. Room is null.
Unable to send message. Room is null.
Unable to send message. Room is null.
Unable to send message. Room is nul"
when i try the AS3 it just says please wait and then nothing happens
tcarr
01-31-2011, 07:05 PM
You aren't connecting to the ES5. You can't send a message until you are logged in and joined a room. Something isn't configured correctly. Have you made any changes to the ES Admin's gateways or are you using the defaults?
The proper logging for the java SimpleChat would show something like this:
Initializing
loadAndConnect
Connection accepted
Active connection: 127.0.0.1, 9899, BinaryTCP, server1
Attempting to login as: Teresa
Login accepted.
You are logged in as: Teresa
Attempting to join room
Joined a room!
jin76
01-31-2011, 07:07 PM
I am using the default settings,
do u want me to upload a screen shot?
I know i am taking alot of your time and for that i am sorry.
tcarr
01-31-2011, 07:08 PM
I don't think a screen shot would help. What does your ES5 log say shortly after you have restarted it?
jin76
01-31-2011, 07:14 PM
here is a screen shot anyways cause it says way too much stuff to type
http://img812.imageshack.us/i/electroserver.jpg/
tcarr
01-31-2011, 07:20 PM
Your ES5 did not start up correctly, so nothing can connect to it. "Address already in use" means that you either have a second instance of ES running, or else there is another application that is using your ES Admin's port. There's a different error message if it's a gateway port taken. Bring up Task Manager, and look at the processes tab. Find all the java processes, and look at the Command line column. Kill any process that mentions ElectroServer (either ES4 or ES5). Start ES5 again, and if you don't see "started successfully" in the log, then there's still a problem (so copy and paste the error message for me). If it starts successfully, try the Java SimpleChat example again.
jin76
01-31-2011, 07:49 PM
ok i tried that, i ended all the things with java in name, there did not seam to be any other instances of electroserver running. When i tried electroserver again it gave the exact same errors.
Would a reinstall of electroserver help?
tcarr
01-31-2011, 07:53 PM
Odds are that you have some other application that is using the port ES5 wants to use. Try editing server/config/Configuration.xml and changing port 8080 to some other port. You will need to make a matching change in your ES Admin's connecting port. Specifically, your local webserver must use a different port than any port used by ES5 (default 8080, 9899, 9899, 8989, 10000, and the RTMP port which I'd have to look up).
jin76
01-31-2011, 07:54 PM
how do i chose another port, i mean what are the options of ports i havent worked with ports before.
tcarr
01-31-2011, 07:56 PM
Just try using port 8081 and see if that works. ES5 doesn't really care what port it uses, as long as that port is available.
jin76
01-31-2011, 08:05 PM
hmmm it still gives the same error.
tcarr
01-31-2011, 08:08 PM
Is it possible to try after shutting down your local webserver? I've seen some webservers configured so that they grab an entire range of ports.
jin76
01-31-2011, 08:20 PM
how do i shut down my local webserver?
tcarr
01-31-2011, 08:23 PM
sorry I got you confused with another forum thread. It keeps saying that address is already in use, even after editing Configuration.xml and changing 8080 to 8081? I think it's time to try killing all the java processes again, uninstalling ES5, and doing a fresh download and install. Something isn't configured correctly, or else you got a bad install.
jin76
01-31-2011, 08:24 PM
alright thanks i will try.
Once again thanks for your dedicated responses.
I will let you know how it went
tcarr
01-31-2011, 08:28 PM
You are welcome. After installing, start it up, verify that you can get in with the ES Admin, and check the log to see if there are any errors. If no errors, test using the SimpleChat clients. If errors, then I'll need the full log, starting from when you tried to start up ES5. You can just email it as an attachment to support AT electrotank.com.
tcarr
01-31-2011, 08:30 PM
One more thing you could try is rebooting Windows. That should clear out all ES instances for sure, unless you have an ES4 running as a service.
jin76
01-31-2011, 08:50 PM
I have emailed support.
tcarr
01-31-2011, 08:52 PM
You are failing to bind the UDP port which is 10000. Can you connect using ES Admin? If you do not need UDP, just delete that listener from the gateways tab. If you do need UDP, try changing to a different port, such as 7500 or 10001. After making changes on the gateways screen, restart ES5.
The relevant part of the log is:
2011-Jan-31 15:40:57:955 [main] ERROR com.electrotank.electroserver5.servers.gateway.Gat ewayServer - Failed opening a listener on /0.0.0.0:10000
2011-Jan-31 15:40:57:958 [main] INFO com.electrotank.electroserver5.servers.gateway.Gat ewayServer - Failure reason:
java.io.IOException: Failed to bind
jin76
01-31-2011, 10:41 PM
It worked !!!!!!
Thank you so much, this super support was the biggest reason that our company chose electroserver.
tcarr
01-31-2011, 10:43 PM
I'm so glad you got it working!
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.