• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

get client's IP adress without servlets or jsp?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am working on a game where I amongst others have a GUI GamepickScreen, Gamechooser, Game and Player object.
Now the server based Gamechooser class handles the login of the user, and being able to choose a session from a list of games.
It sends that information to the client based GUI Gamepickscreen. During the login method a new Player instance is created with the name filled in on the screen.
That Player instance is thus on the server side as well and in it's constructor it stores the playername and IP address.
How can I fetch the public IP address of the client so that a server-based class can store it?
I found a few things when searching but most are about webbased javascript + JSP combinations. This is a regular networked application, not via http.

thanks
Deb
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the connection being established? If it involves a ServerSocket, then its accept() method returns a Socket object that can be used to obtain the client IP address.
 
Deborah Larsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply.
I use RMI. I did not use ServerSocket before, but I looked it up and see that this is part of the RMI library.
This is what I used previously in a simpler application.


I am not sure at the moment if involving the serversocket is a better idea for this or in general.
Guess I'll read up on the topic.

Deb
 
Marshal
Posts: 74031
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving thread as too difficult for "beginning."
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the static method "getClientHost()" in the class java.rmi.server.RemoteServer .
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic