• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Would this be the correct design/logic for a "log on" program?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so I'm writing a messenger-like program for a (don't laugh) local loop .
I realize that there are some "what-ifs" such as two people logging on with the same username in the same session, but that's not important now

I'll keep a table in some DBMS with the following information:

UserName
PortNumber

I already have three user-names registered.
PortNumber are currently null since none of the users online at the moment.

First, we get the server running to accept connections, a username must be provided when requesting the connection (no passwords for the sake of simplicity).

If the username is in the DB, get the port number from the incoming request and map it to the username in the DB , otherwise, reject connection.

Same for requesting to disconnect, look up the name, if it exists (it should, since I'm already connected), set the port back to NULL and close the connections/sockets.

I should be able to check the status of the user at any time by checking if the port number is null or not.

Does everything sound correct? Are there any tutorials out there that touch on this subject? Doesn't have to be in Java, I just want to get the logic down and read on the more common pitfalls.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well your logic sounds effective enough for some trial coding, but how do you intend to obtain the port number. I right now am trying to figure out how to get a port number for an incoming request - the sample server in the nio folder requires that one provide a socket to listen on in the constructor for the server. It is ahead of me how the network/server/local machine negotiate socket numbers except that sockets for local prototyping should be between 49152 through 65535

source: http://www.iana.org/assignments/port-numbers

I wrote a socket class that made sure the port number was in this range. I will share the code with you if you want.

I ended up copying it over to my working project and went to read the docs on sockets. Got nowhere.

Logic sounds good enough to do some initial trial coding, but how about using session id or someting ?
[ October 13, 2007: Message edited by: Nicholas Jordan ]
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't really look into it, I just assumed class Socket had a getter method for that.

Even if I can't do that from the server, I can always have the port requesting to connect to also send it's number, no? I didn't really give it much thought and I assumed it was too simple.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see what's the point of storing the port number. If you just want a boolean variable that says whether the user is online, then just use a boolean column in your database.
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because what if someone logs in and wants to send a message to that user through his username? Need to know what port to send to.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Tarek Khojah: ]   Because what if someone logs in and wants to send a message to that user through his username? Need to know what port to send to.
I think we are going to get crossways somehow here, with whom and for what, I do not know; but I just now suddenly have several days to work on this and have a copy of Java Network Programming by O'Reilly and will get back with you on this if I have any usefull progress to report.

I have a stack of books to get through and will be saturated, so in the interim be sure to look into Network Topology as a google search term because without it, you have no idea how deeply recursive in entrenched computer science this work can, and should, delve into.

See: Train Scheduling problem

There are chat clients that are available in java sample sources, it would not impede my project to write one right now. Anyone with have any input on this ?

I can write these things for throwaway if I know how the underlying system works, sometimes I plug them in as modules and it saves me a lot of what Extreme Programming calls traditional assumption because I can do what xp calls unit testing during concepting code to fulfill posted need.
reply
    Bookmark Topic Watch Topic
  • New Topic