Applet's getParameter() and Socket

When my client applet connects to the server, I use...
[code]Socket connection;
connection = new Socket( "10.105.0.13" ,12345);//IP of running server
[/code]
This works fine, but when I try to use Applets getParameter() to rerieve the IP stored in the applets html file like so...
[code]

TicTacToeClient






[/code]
and change the code to...
[code]
connection = new Socket( getParameter("serverIP"),12345);
[/code]
I get a null pointer exception (getParameter() returns null if it doesn't find the param name).

Thanks for any help.
merlin_bar

Comments

  • : When my client applet connects to the server, I use...
    : [code]Socket connection;
    : connection = new Socket( "10.105.0.13" ,12345);//IP of running server
    : [/code]
    : This works fine, but when I try to use Applets getParameter() to rerieve the IP stored in the applets html file like so...
    : [code]
    :
    : TicTacToeClient
    :
    :
    :
    :
    :
    :
    : [/code]
    : and change the code to...
    : [code]
    : connection = new Socket( getParameter("serverIP"),12345);
    : [/code]
    : I get a null pointer exception (getParameter() returns null if it doesn't find the param name).
    :
    : Thanks for any help.
    : merlin_bar
    :
    :

    It's quite a long time ago that I've written Applets, but as much as I remember, the parameter shouldn't be in quotation-marks:

    [code]

    TicTacToeClient






    [/code]

    I hope that helped, though I'm really not sure.

    tron.
  • : When my client applet connects to the server, I use...
    : [code]Socket connection;
    : connection = new Socket( "10.105.0.13" ,12345);//IP of running server
    : [/code]
    : This works fine, but when I try to use Applets getParameter() to rerieve the IP stored in the applets html file like so...
    : [code]
    :
    : TicTacToeClient
    :
    :
    :
    :
    :
    :
    : [/code]
    : and change the code to...
    : [code]
    : connection = new Socket( getParameter("serverIP"),12345);
    : [/code]
    : I get a null pointer exception (getParameter() returns null if it doesn't find the param name).
    :
    : Thanks for any help.
    : merlin_bar
    :
    :

    Since applets cannot access any server other than the one they were requested you might want to do this a little differently. Here is one suggestion:
    [code]
    connection = new Socket( getCodeBase().getHost(),12345);
    [/code]
    This way you will be able to deploy this applet on any server without any code change and there is no need to have a param tag in your applet descriptor on the html page.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion