Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[JAVA] Tracking Individual Users


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Shippou   Members   -  Reputation: 1714

Like
0Likes
Like

Posted 28 June 2012 - 02:35 PM

I've been trying to figure out how to create a multi user server for quite some time now, and have kept running into the same issue - how to track and manipulate individual users.
I found a code example, and turned it into a working Client / Server chat program. Here is my version of the code for reference, and to keep this post relatively short .... http://reviewerrick.blogspot.com/2012/06/working-java-socket-server-client.html

That code creates a new thread every time some one connects to the server, and they can make their own user name.

What I have been banging my head off a wall, is there is no way that I know of, to send data to only one of the connected clients.
All processed data is sent to all clients, and as far as I know of, there are no ways to access specific users ( by name ).
The main loop is an issue, also, due to the fact I can not process anything outside of the threads.

I'd love to create a session number for each client connected, and use that to individually manipulate the users.

I've been trolling Google for a very long time now on various subjects of networking, users, and the like .... lots of information on servers, no information on individual users.

 Reactions To Technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things.

- Douglas Adams 2002


 


Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5538

Like
0Likes
Like

Posted 28 June 2012 - 11:09 PM

That code creates a new thread every time some one connects to the server


That's a terrible idea! The FAQ for the forums talks about why.

Regarding your question: Each user has either a socket (for TCP) or a destination IP/port (for UDP.) Find the user by name (use a std::tr1::unordered_map or std::map or whatever) and send the message only to that user's endpoint.

enum Bool { True, False, FileNotFound };

#3 Xanather   Members   -  Reputation: 712

Like
0Likes
Like

Posted 29 June 2012 - 02:31 AM

I had the same problem as you. What I have done recently is to basically create a list of a Client class (make your own), inside that class can contains socket information, unique id assigned to that user, any other client-specific information. The client class can even make instances of other classes, or structs, that could contain more information (what level am I in a multi-player RPG?). Since you'll probably have a server game loop, get the server to check over each connected client in the Client list, extract every piece of networked buffered data available from each client and then depending on how you are making sense of messages process that message for that client and do what so ever accordingly.

Now that ive said that just look for the client in the Client list with the correct uniqueid that you want to send data to and send it to only that client.

Edited by Xanather, 29 June 2012 - 02:34 AM.


#4 Shippou   Members   -  Reputation: 1714

Like
0Likes
Like

Posted 30 June 2012 - 12:16 PM

Does the socket object contain the unique information about the user, or do I have to extract a specific part of it ?
If the whole socket object can be used, I could create a hashmap that has the generated session number, and the socket object of each user, which is referenced by the rest of the code when ever it does something relevant to the specific user.

Edited by Shippou, 30 June 2012 - 12:18 PM.

 Reactions To Technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things.

- Douglas Adams 2002


 


#5 anonymous22   Members   -  Reputation: 199

Like
0Likes
Like

Posted 30 June 2012 - 01:07 PM

What Xanather described is exactly, word for word, what Microsoft did in their .Net framework implementation of System.Net.TcpClient/UdpClient!!!

#6 hplus0603   Moderators   -  Reputation: 5538

Like
0Likes
Like

Posted 30 June 2012 - 06:59 PM

What Xanather described is exactly, word for word, what Microsoft did in their .Net framework


Really? They use a linear list of all TcpClients? That's pretty inefficient compared to a hash table, or even better, just using an implicit reference where needed and no central look-up at all.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS