Results 1 to 6 of 6
  1. #1
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Smile 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?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default

    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....

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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).

  5. #5
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default

    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?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Socket question
    By Psyclone in forum Networking
    Replies: 0
    Last Post: 03-10-2010, 04:12 AM
  2. One socket and multiple threads
    By DC200 in forum Networking
    Replies: 1
    Last Post: 12-30-2009, 07:32 AM
  3. Question About Using Serial Ports
    By GoodAsh03 in forum New To Java
    Replies: 3
    Last Post: 07-28-2009, 06:11 AM
  4. Applets and serial ports question
    By kenshinofkin in forum Java Applets
    Replies: 1
    Last Post: 02-27-2009, 12:30 AM
  5. Programming Socket Question
    By paul in forum Networking
    Replies: 1
    Last Post: 07-30-2007, 08:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •