IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
Author

I need help improving this chat server and chat client!

Cody Long
Ranch Hand

Joined: Jan 01, 2009
Messages: 58

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

Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8832

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

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Messages: 58

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.

This message was edited 1 time. Last update was at by Cody Long


Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Messages: 58

thank you for your help i figured out how to do it in time.

Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Henry Wong
author
Bartender

Joined: Sep 28, 2004
Messages: 10017

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

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Messages: 58

yeah but thankfully newbishness seems to come off pretty quick sometimes!

Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
replay challenge