-
continuously testing for the existence of the client program?
OK,
I'm going to have a server that keeps track of online users.
When a client program logs onto the server [LOGON, username, ipaddress], the
client's data [username, ip address] will be added to the list of online
users.
At the same time, the entire list of online users will be sent out to the
current client's online user JInternalFrame.
If the user quits the client program, upon detecting the windowClosing
method, inside the stop() method, I will write a data stream [LOGOUT,
username, ipaddress] back to the server to have this username removed from
the server.
These two steps are OK for me to write. However, let's say, if the client
hangs or ran into some exceptions, the server will need a way to test if the
user is still online. So, if the client program do not respond to the
request from the server, the server itself will remove the user from the
online users list and re-broadcast the current online users list to all
other connected clients.
How should I go about doing this? Checking for the existence of the client
program to see whether it's still 'alive' or not.
And, can I keep the online users that contains two fields [username,
ipaddress] in a Vector()?
How do I write them and how do I retrieve them?
Thanks.
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
---------------------------------------------------------------
-
RE: continuously testing for the existence of the client program?
Hello Winghoe
You can easily keep the online users that contains two fields [username, ipaddress] in a Vector.
Refer code -
import java.net.InerAddress;
public class User {
private String username;
private InetAddress IPAddress;
public User(String name, InetAddress ipAddress) {
username = name;
IPAddress = ipAddress;
}
public String getUsername {return username;}
public InetAddress getIPAddress (return IPAddress:}
public void setUsername (String name) {username = name
public void setIPAddress(InetAddress addr) {
IPAddress = addr;
}
}
import java.util.*;
public class Test {
public static void main(String args[]) {
Vector vector = new Vector();
InetAddress addr = null;
try {addr = InetAddress.getLocalHost();}
catch(Exception e) {}
User user1 = new User("Winghoe", addr);
vector.addElement(user1);
//retreive values from vecor
for (int 1=0; i<vecor.size; i++) {
User u1 = (User)vector.elementAt(i);
System.out.println(u1.getUsername());
System.out.println(u1.getIPAddress());
}
}
}
If you find the above solution useful, let me know.
>OK,
>I'm going to have a server that keeps track of online users.
>
>When a client program logs onto the server [LOGON, username, ipaddress], the
>client's data [username, ip address] will be added to the list of online
>users.
>
>At the same time, the entire list of online users will be sent out to the
>current client's online user JInternalFrame.
>
>If the user quits the client program, upon detecting the windowClosing
>method, inside the stop() method, I will write a data stream [LOGOUT,
>username, ipaddress] back to the server to have this username removed from
>the server.
>
>These two steps are OK for me to write. However, let's say, if the client
>hangs or ran into some exceptions, the server will need a way to test if the
>user is still online. So, if the client program do not respond to the
>request from the server, the server itself will remove the user from the
>online users list and re-broadcast the current online users list to all
>other connected clients.
>
>How should I go about doing this? Checking for the existence of the client
>program to see whether it's still 'alive' or not.
>
>And, can I keep the online users that contains two fields [username,
>ipaddress] in a Vector()?
>
>How do I write them and how do I retrieve them?
>
>Thanks.
>
>
>
>--
>
>
>
>Best Regards,
>Wing Hoe
>---------------------------------------------------------------
>ICQ: 2213281
>Email: winghoe@hotmail.com
>www: http://pwp.maxis.net.my/winghoe
>---------------------------------------------------------------
>
>
>
>
>
>
Message sent from http://www.aewnet.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks