This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Creating a Java chat server using sockets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Creating a Java chat server using sockets" Watch "Creating a Java chat server using sockets" New topic
Author

Creating a Java chat server using sockets

Rachel Smiths
Greenhorn

Joined: Feb 26, 2013
Posts: 1
I have the following homework assignment that i need to complete
Instructions: Write a program in Java that uses sockets to act as a chat server.

Use the String[] args parameter of the main method to allow command-line entry of the listening socket. By default, the socket should be 23, but if a command-line argument is passed, open a socket on the appropriate port.

Your chat program should require a signon before entering the chat room. The signon should be a simple string, without any authentication (duplicate names are allowed).

When a user enters the chat room, a message should be sent to all existing users.

While in the chat room, anything typed (other than exit or quit) should be sent to all chat room users, except for the sender, along with a prefix of who sent the message. For example, if user “bif” types “hello”, all users except bif should then see “bif: hello”.

A command of “exit” or “quit” will cause the user to exit the chat room and be disconnected. A message should be sent to all other users in the chat room.

You can work in pairs on this project. You may help other students with hints on where to look in the book or the Internet to find information on socket programming, but all code should be the work of yourself or the pair you are working in.

You can test your program using telnet clients (available in Mac, Windows, and Linux OSs as standard utilities)


I have done a lot of research and basically know how to create sockets, servers, and clients. Im just not sure where to start or how to organize it. I know nothing about telnet. i need a really good tutorial or a basic diagram on how to implement the code such as: create a socket, connect using a server, type in words. I'm just not sure of the diagram i need to follow or what classes i need. any help would be greatly appreciated.

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hi Rachel,

Welcome to CodeRanch!

As you know the basics of sockets, you can start with very basic client-server application and follow step-by-step development:

1) Create 1 server and two clients. See if those clients can communicate with each other.
2) Modify the server to accept more client connection requests during runtime (you'll need to create a listener thread for this).
3) See if multiple clients can communicate with each other.

Once these things work out, you may modify the code to notify all clients when a new client is registered etc.

For a very good treatment to such issues, I would highly recommend Java Network Programming by Harold.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a Java chat server using sockets
 
Similar Threads
conference chat app
Guidance on Chat Server structures
servlet to another client
Problem with Multi-User Server__Please need Help!
ObjectInputStream and Vector question?