• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

[Assignment] Need to make public server

 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I got an assignment to develop public chat server.

Requirement:

Server: A server should accept a client request. On each request it will check the userName entered by the client in its database. If userName is unique then it makes entry in it and send notification to all the connected client. All the client can type and send their message which are seeing by all the clients.

client: Whenever client is connected , it asked for the username. Once username is entered by the user it got validated with the existing data on the server end and if it unique then client can able to login otherwise it shows "Already present warning" and asked user
to again type.

Now i am trying to implement the same. Got confused on server side. I am opening a new thread on each client request. Whenever a new thread is opened it set the IO stream and receive the userName from the client. Then server checked it in its database(i used Map where Name is key and Socket is the value). If it is not present then send "No". Server then sends new user login to all the user connected. after that it start receiving message from the client and then send that to all.

I am confused in last part. How to send message to all and also whether synchronization is allowed or not. If synchronized is there only 1 client can write a time but in reality several users can write at a time. My server code is as below:




I am confused here:
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still not able to figure out for this 2 methods .. any suggestion??
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Able to figured it out.. But still confused if i require any synchronization or not. As i see it works fine without synchronization.. Any suggestion...?
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No one responding . Am i asking wrong question or what?
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tushar Goel wrote:No one responding . Am i asking wrong question or what?


Not really, but this really isn't beginners stuff. I've been using Java for 12 years and I've never written a chat room.

Your questions are also rather vague and you've presented us with a LOT of code. We're all volunteers here, so chances are that noone is going to want to spend hours on just your thread.

My suggestion: Try and narrow down your scope and ask questions about specific problems. You might also want to read this page and this one; not to mention our own HowToAskQuestionsOnJavaRanch (←click).

My only general thought is that if you have several potential users going after the same data, then you will generally need synchronization; but whether that's in your Java program or your database (which are generally designed to deal with it) I can't really say.

In the meantime, I will move your topic to a more general forum. You may get better results.

Winston
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks Winston.. I will keep this in my mind next time i ask any question.. By the way i only have problem in 2 methods which i pasted separately...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic