Simple chat program using the ocsf framework
Explore the project
Report Bug
·
Request Feature
Simple chat program using the ocsf framework to work with OpDemand.
OCSF is a simple framework that provides TCP-based client-server connections.
Without the framework, we would need several labs just to implement network communication.
A framework reduces development time and usually improves software quality. Most frameworks are extensively tested both by developers and users, so they have fewer bugs and a better architecture than software written from scratch.
The Object Client-Server Framework (OCSF) provides client-server communications using TCP/IP.
The OCSF framework is described in a textbook by Lethbridge (chapter on OCSF is on class web).
You can write a console-based client or GUI client
Create a client as a subclass of AbstractClient or ObservableClient. that does this:
- Connect to the server and display a "connected" message.
- Show any messages from the server. Print on console or display in a GUI field.
- Accept input from the user and send it to the server.
- Close the connection when you want to quit. If you write a GUI, there should be a "Disconnect" button. On the console, if the user enters "quit" then disconnect.
Write your own server using OCSF's AbstractServer class.
You should create a server that requires clients to identify themselves, so you know which user is connected on which ClientConnection object.
- Write a class that extends AbstractServer or ObservableServer (both classes have the same methods).
- When a new client connects, you should wait for the client to (somehow) identify the user. Design your own solution to this. The ClientConnection object has a map that you can use to store arbitrary values. You can use this to store the user's name. For example: client.setInfo("username", clientname );
- When a user logs in, servers send a message to all clients telling them "Clientname connected" (you can design the format of this message. It doesn't have to be a String.)
- When a logged-in client sends a one-to-one message like this:
To: Anchan
Hi, Anchan. How are you?
your server should find a client connection with login name "Anchan" and send the message. Be sure to tell Anchan who the message is from! - If a client sends the String message "Logout" then close the client connection and tell all other clients "Anchan logged off".
- If the client sends any other message, the server responds that message is not recognized.
From command line
cd
into directory.
Compile with javac ServerConsole.java
Then run with java ServerConsole
In another terminal
Compile with javac ClientConsole.java
Then run with java ClientConsole loginID [host [port]]
where loginID, host and port should be replaced (for example: java ClientConsole client1 localhost 5555)
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Benedek Balazs - LinkedIn profile - ME - [email protected]
Project Link: GitHub - blasio99 - SimpleChatOCSF
Lethbridge and Lagariere, Object-Oriented Software Engineering, 2E. Textbook describes use of OCSF and a chat project.
A standard, high-performance framework for chat and other applications is XMPP.
XMPP is a standard protocol for real-time messaging; XMPP was originally called Jabber. Google Talk uses XMPP. You can use XMPP to write your own Chat client or other Internet application. There are many several free XMPP servers (such as Jabberd and OpenFire), clients, and libraries. XMPP can be used for more than just chat. SMACK is an open-source XMPP library for Java. It is used by several chat applications. http://www.igniterealtime.org/projects/smack/
- How to use SMACK to write a Java client: http://www.javacodegeeks.com/2010/09/xmpp-imwith-smack-for-java.html
- Other two articles in the same series describe infrastructure for using XMPP.
XEP-0045 Multi-User Chat. Protocol for a multi-user chat using XMPP. http://xmpp.org/extensions/xep0045.html#bizrules-message