Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Identifying User Sockets  RSS feed

 
Dean Hampson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I have a login/register GUI that selects or saves information from or into the database. Then I have a multi user chat client frame that is set visible once that user logs in. From here I'd like the program to know which user is sending messages without having to getPort () on the server side and scan for it in the database to know their username every time they hit the Send button. I'd very much appreciate any help and suggestions relating to this topic. Thanks!
 
Paul Clapham
Sheriff
Posts: 22106
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see what the problem is with that solution, except for maybe the idea of using a database to map the port number to the user information. You wouldn't really want those port numbers to persist after the server is shut down. In any case you need a data structure -- I would keep it in memory -- where you can use the port number as a key and get the user information as data. Presumably when the user first connects to the server they transmit a user ID or something immediately, no?
 
Ron McLeod
Saloon Keeper
Posts: 1344
193
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternative, if you don't want to use the IP address and port number to indentify the user, would be to have the server assign a unique identifier/token/cookie to the client and have the client provide this with each subsequent communication with the server.

 
Dean Hampson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I could use an object ArrayList that adds the remote socket ip and port every time the user logs in but then I'd have to keep scanning through the ArrayList for the username every time that user chats or enters a chat command.
Session tokens sounds great but I would think there's a lot involved with these. How would one go about learning this? It's implemented in Java?
 
Paul Clapham
Sheriff
Posts: 22106
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dean Hampson wrote:Yeah I could use an object ArrayList that adds the remote socket ip and port every time the user logs in but then I'd have to keep scanning through the ArrayList for the username every time that user chats or enters a chat command.


I'm still missing why you think this is a problem. Sure, a Map would be better, but I don't see why you object to scanning a list.
 
Ron McLeod
Saloon Keeper
Posts: 1344
193
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dean Hampson wrote:Session tokens sounds great but I would think there's a lot involved with these. How would one go about learning this? It's implemented in Java?

Well, you would build it in to the application protocol which will be used for the client/server communications.

Since your original question was related to sockets, it seems like the client and server will communicate over a network connection.  Have you thought about how the client will log-in or chat over the network connection?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!