Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-19-2005, 06:12 AM   #1 (permalink)
j.gohel
Code Monkey
 
Join Date: Apr 2005
Posts: 68
j.gohel is on a distinguished road
get IP dynamically

Hello all
I am making a chat application in which i use JSP and Servlet
Now I have provided the normal login page that is in swing that calls the servlet and does the authentication with the server against databse

Now i would only be giving the swing gui to the client in a jar
But the IP that i pass while compiling and making a jar of swing client is static

Now every time the server changes i need to recompile the class file
Taking the case of yahoo that must be having many servers but the client never needs to specify the IP

Is there any way that my client can get the IP without me having to recompile it everytime before giving it to the client

Thanks
Regards
Jignesh
j.gohel is offline   Reply With Quote
Old 04-19-2005, 08:06 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,140
Belisarius is on a distinguished road
InetAddress.getLocalHost();
__________________
GitS
Belisarius is offline   Reply With Quote
Old 04-19-2005, 03:44 PM   #3 (permalink)
webcomplete.com
Registered User
 
Join Date: Mar 2005
Posts: 14
webcomplete.com is on a distinguished road
Im not sure if your question is clear - but I guess you mean that the client need to point to the server's ip? so that you can login and perform transactions?

if thats the case, why dont you just use a domain name? you can make a domain name point to an ip via DNS. And if your client needs to go through a certain port, then you can connect your client like: "chat.mydomain.com:8888"

and when the ip changes, you just need to update the domain to the new ip instead of recompiling the program and forcing everyone to download a new copy of the client.

note however, most dns updates takes as little as 1 hour to as much as 48 hours to propagate worldwide - but surely this is better than recompiling a new client. on the other hand, your server should really be on a static ip. or you can get a hosting service for java with sql server and static ip for about 10 dollars a month.
webcomplete.com is offline   Reply With Quote
Old 04-20-2005, 05:10 AM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,140
Belisarius is on a distinguished road
Ah, if you need to find the server, that's what things like Jini are for; automatic serivce discovery. Damned if I know how to make it work though. It's a bit more robust than just pointing it at a DNS address, but it's a bit more complicated too.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-22-2005, 06:38 PM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
If you have a website you could also host a file or redirect on that which client reads and your server updates.

So if your IP changes it updates mydomain.com/server.ip
Then the client reads mydomain.com/server.ip and use the provided ip to connect.

Another option is to use a HTTP/1.0 status code
write for example a PHP script that does:
PHP Code:
<?php
// Many pre-HTTP/1.1 user agents do not understand the 303 so we use 302
header('HTTP/1.0 302 Found');
header('Location: 123.45.67.89:8888');
Ofcourse the client should understand the 302 and react on that.
DJMaze is offline   Reply With Quote
Old 05-23-2005, 02:22 AM   #6 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,140
Belisarius is on a distinguished road
That *really* won't work for him - he was needing something that he can put in a compiled class to discover the server (needless to say, you can't simply insert PHP into a Java class). If he already knew the address (DNS or IP), he wouldn't be having these problems. Unless he was talking about finding his own IP, we've been working on the assumption that he has no clue as to where his server is located any given day. Your solution only works if you know the DNS address, which isn't an assumption here.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
making a 3 column table dynamically sde PHP 8 08-28-2004 07:14 PM
Adjust physical output size dynamically metazai PHP 8 08-24-2004 10:15 AM
subdomains dynamically sde Linux / BSD / OS X 12 03-22-2004 03:57 PM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 08:50 AM


All times are GMT -8. The time now is 02:12 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting