• 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

TCP Threaded Server Client Question

 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone,

I am working on a small chat program for one of my classes, where users can connect to a server and create groups to chat in. When the user connects a new thread is created for the user-server to interact in, inside this thread I add a user to a list of users that have already connected. I am running into the issue an where inside my thread I am adding a user to the list of users but for some reason when I check to the number of users that have connected on my client program code, is says the number of users is 0.

ChatServer:


ThreadHandler:


ChatClient:


Sorry for the long post, any help would be awesome.

Thanks,
Hunter
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the thing is that ChatClient runs in its own JVM and thus has its own version of ChatServer. So the number of users that you're seeing is not of the server.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does ChatClient run in its own JVM? Also I've never encountered this problem before, any ideas on what I can change to remedy this?


Hunter
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every time you type in your console: java className, a new JVM is started. I wouldn't classify this as a problem. You can run your programs in a single JVM but that isn't really the idea behind communicating through sockets. You could ask the server what the number of users is at that time and print that.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server has a method getClients() which returns a List of all the clients connected to the server. The size of that list should be the number of clients that connected to the server, so when I call that method and test it's size isn't that the same as asking the server for the number of users?

Hunter
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 Is that you currently have and 2 is what you want. You'll need to communicate through the sockets to ask what the number of users is.
Situation.png
[Thumbnail for Situation.png]
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok that cleared my confusion up thank you.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I could help.
reply
    Bookmark Topic Watch Topic
  • New Topic