Results 1 to 6 of 6
Thread: Multiple Socket Ports Question
- 11-09-2010, 11:44 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
Multiple Socket Ports Question
Hello,
I want to write a java japplet application which will handle multiple chat rooms with sockets. There can be 1 or more chat rooms running at a time with 1 or more users in each chat room.
Would each chat room get its own port number that the socket is using? And everyone in that chat room would use the same port number? If so, how would you dynamically choose a port number each time a chat room is created?
I'm aware I probably could use one port number for everything, but this would probably be very inefficient, right?
-
I'm no pro at this, but I would assume that each chat room would have it's own logical server right? And so each ServerSocket would choose which port it will listen on.
- 11-10-2010, 01:40 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
so you would need to know in advance the max amount of rooms you would have? For example, you would have ports and sockets ready to go for 100 chat rooms and when someone starts a chat room, it will start the socket....
-
No, you could start ServerSockets on the fly. No need to have them "ready" in advance. If you call the ServerSocket constructor without a parameter it will use a randomly available port (I think).
- 11-10-2010, 02:00 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
Maybe they can create on the fly, but if it uses a random port number, how does the client know what port to use when it is trying to connect to it?
-
The ServerSocket object can always get the port number via it's getLocalPort method, but like I said, I'm no pro at this.
Similar Threads
-
Socket question
By Psyclone in forum NetworkingReplies: 0Last Post: 03-10-2010, 03:12 AM -
One socket and multiple threads
By DC200 in forum NetworkingReplies: 1Last Post: 12-30-2009, 06:32 AM -
Question About Using Serial Ports
By GoodAsh03 in forum New To JavaReplies: 3Last Post: 07-28-2009, 05:11 AM -
Applets and serial ports question
By kenshinofkin in forum Java AppletsReplies: 1Last Post: 02-26-2009, 11:30 PM -
Programming Socket Question
By paul in forum NetworkingReplies: 1Last Post: 07-30-2007, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks