2

I'm putting together a framework for some games via webservices, which for various reasons need to run without an application container.

At this point, all I'm after is that each player will authenticate, and hit the login service. The login service does not return until all players have logged in, so the players know that once their call is complete they can begin playing.

The issue I'm having is that this works fine without the authentication, but as soon as I enable the authentication, the first player authenticates and connects correctly, but the second player cannot connect as long as the first player is waiting for the login service to return.

The services look as follows:

public void login()
{
    Game game = Game.getInstance();
    while (game.getStatus() != Status.RUNNING)
    {
        try
        {
            Thread.sleep(10);               
        } 
        catch (InterruptedException e)
        {
            // swallow it, doesn't matter
        }
    }
}

The clients look like (stripped down to the connect logic):

public void clientLogin()
{
    Authenticator.setDefault(new Authenticator()
    {
        @Override
        protected PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(getUsername(), getPassword());
        }
    });

    QName qName = new QName("http://namespace/", "ChallengeService");
    URL url = new URL(endPoint);
    ChallengeService wsClient = new ChallengeService(url, qName);
    System.out.println("Got Client");
    wsPort = wsClient.getChallengePort();
    wsPort.login();
}

The server is started with:

public void startServer()
{
    server.start();
    endpoint = Endpoint.create(new ChallengeService());
    server = HttpServer.create(new InetSocketAddress(7070), 5);
    context = server.createContext("/Challenge/ChallengeService");
    context.setAuthenticator(new StandaloneAuthenticator("Challenge")); // disabling this works
    endpoint.publish(context);
}

Any ideas?

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
  • *"..which for various reasons.."* I'm listening. What are the reasons? – Andrew Thompson Mar 08 '13 at 08:47
  • 1
    This game framework, when it is actually running, will be running in a managed environment. The players will be coding clients in Java or C#, and we want to give them an offline testing mechanism that is not dependent on our servers. I can't expect the C# players to install an application server to do the testing (this is for a coding competition with a reasonable prize), so I need it to be able to run standalone without an application server. – Evan Knowles Mar 08 '13 at 08:49
  • *"I can't expect the C# players to install an application server to do the testing (this is for a coding competition with a reasonable prize)"* I think it is quite reasonable to expect the developer to install an (free) app. server. Heck, to do Android dev. I had to install Netbeans (at great expense to my bandwidth). – Andrew Thompson Mar 08 '13 at 08:52
  • 1
    People are incredibly lazy - we ran this competition last year and people would give up for the smallest reason. C# guys are scared of Java servers it seems. – Evan Knowles Mar 08 '13 at 08:53
  • *"people would give up for the smallest reason."* Seems like they are not worthy entrants. I'm just sayin'.. – Andrew Thompson Mar 08 '13 at 08:55
  • 1
    Yeah, I agree with you totally, but we run the competition for the publicity mostly so we need as many entrants as we can get. – Evan Knowles Mar 08 '13 at 08:55
  • Sounds like the `StandaloneAuthenticator` is blocked. Is that a library class (I couldn't find that name w/ a simple search)? Your requirement that the "login service does not return" might cause problems w/ the auth/login process. My understanding was that it's common for systems to delegate this to a single worker (or set of workers), somewhat independent of the connections themselves, in which case having your program try to block there might be tricky. – SeKa Mar 17 '13 at 23:21
  • Can you put a debug point in the `login` code to see if the second player ever enters the loop? If not, then it's the Authenticator as `SeKa` noted. If it is, then you have a bug in your `getStatus` logic that allows the first player through (likely a mixed up `if` statement). It seems like the latter because the first player makes it through. – pickypg Mar 19 '13 at 01:36
  • Do you have any synchronized methods in the Game class? – Dror Bereznitsky Mar 19 '13 at 19:26
  • Agree with SeKa, it seems your authentication code obtains a single lock, hence multiple HTTPServer threads couldn't execute it concurrently. Have you got a static synchronized method, or a synchronized block that uses a single object anywhere? – gerrytan Mar 19 '13 at 22:17
  • Hey - there are no synchronized methods anywhere at the moment. The StandAlone authenticator extends BasicAuthenticator and at the moment only checks if the username begins with test. – Evan Knowles Mar 22 '13 at 13:52

0 Answers0