This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help improving this chat server and chat client!

 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help me make this server more secure and the chat client looking a little cooler. Also can you show me how to make it where a user types in their names and it shows up next to the text that they sent? right now it just shows what a person wrote, not wich person. thank you.

ChatServer.Java


ChatClient.java
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server has to inform the clients on who has sent the message. You can do that by either sending the user name from the client with the message, or by recognizing the user from the specific ClientHandler. I'd say the first solution is the easiest, and it keeps user names local to one place.

As for security, you could add both a welcome message and a departure message. A client first sends the welcome message when connected, and the server rejects the socket if the welcome message does not match. If a client disconnects it can send a departure message that allows your server to nicely clean up its resources (and inform other users that the user has left).
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:The server has to inform the clients on who has sent the message. You can do that by either sending the user name from the client with the message, or by recognizing the user from the specific ClientHandler. I'd say the first solution is the easiest, and it keeps user names local to one place.

As for security, you could add both a welcome message and a departure message. A client first sends the welcome message when connected, and the server rejects the socket if the welcome message does not match. If a client disconnects it can send a departure message that allows your server to nicely clean up its resources (and inform other users that the user has left).


how would you do that? i am a beginning programmer and got the server code from a friend and i dont know where he got it. the client part i made via the server info but i still can not figure out how to get the username [art and how to add more security.
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your help i figured out how to do it in time.
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Long wrote:thank you for your help i figured out how to do it in time.


Well, I am sure that once you figure out the code, then Rob suggestions will start to make sense. It is hard to change code when you don't know how it works -- especially for a beginner.

Henry
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah but thankfully newbishness seems to come off pretty quick sometimes!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic