How to build a high quality Client/Server Java application – a Java Chat Client/Server example Part5

April 5th, 2006

Part1 , Part2 , Part3 , Part4 ,Part5

Now that we have tested out Sockets and threads, we need to combine the two to make a concurrent server . A concurrent sever can handle more than one client at a time. It works like the old time phone operators. It gets a connecting client call, then it creates a thread to handle that call, and then goes back to listen for the next caller.

Concurrent Sever example

Client 3

Server 3

Run server and then start two instances of the client3. You should see in the server console that it is handling both users concurrently, hence a concurrent server.


Java,/client/server,course,chat,sockets,network,swing

How to build a high quality Client/Server Java application – a Java Chat Client/Server example Part4

March 20th, 2006

Part1 , Part2 , Part3 , Part4 ,Part5

In the next example we will start 3 threads. Each thread will print a unique string and then go to sleep for set time and then print another string and so on. There are two ways to create a thread: One is to subclass the Thread class the other is to implement “runnable’. I will show you how to do it both ways. Most of the time you want to subclass a thread, but it some situations it is far easier to implement Runnable. For example when you have to pass a great amount of data to the thread class it may be easier to just create the thread in the class you are in.

Extending Thread example

Implementing Runnable example


Java,/client/server,course,chat,sockets,network

How to build a high quality Client/Server Java application – a Java Chat Client/Server example Part3

March 15th, 2006

Part1 , Part2 , Part3 , Part4 ,Part5

The next example is to add a level of complexity to our first example.

The client will connect to the server, send 20 messages, and then terminate. The server will listen for a client, read messages, and print out the messages from that client until the client disconnects. Then the server will go back and wait for the next client.

After testing our new servers and clients I am now comfortable with Java.net technology. And I am ready to incorporate more.

Client

Server


Java,/client/server,course,chat,sockets,network

How to build a high quality Client/Server Java application – a Java Chat Client/Server example Part2

March 8th, 2006

Part1 , Part2 , Part3 , Part4 ,Part5

Well since it is a network application, we should start by writing some simple network code to make sure that we fully understand the technology.

The first simple code we are going to write is an application that a client sends one message across the net and the server gets that message and prints it out.

In order for you to send a message across the internet you need two things the IP address of the machine and the port number the server is listening at. You see all internet based software listens to a port. For example Web servers listen to port 80.

The IP address we are going to use is “localhost” which means your current local machine/desktop. The IP address we are choosing is 51234. We could have picked any number above 1024.

Here is the example:

Client1

Server1

Run the server first, then the client.


Java,/client/server,course,chat,sockets,network

How to build a high quality Client/Server Java application – a Java Chat Client/Server example Part1

March 8th, 2006

Part1 , Part2 , Part3 , Part4 ,Part5

The best way to show you how to build a high quality Java application is to take you through building one.

We are going to build a Chat application from scratch. While we are building this Chat, I will introduce many concepts to help you build a high quality application.

Ok let’s get started.

First thing is to define a scope. In other words what we are going to build.

SCOPE: The Chat application we are going to build will be a client/sever application. The client can run on its own or as an Applet. The chat application will have multiple chat rooms and features like whisper (allows a user to whisper to another user). It would also be nice to add a white board so people can draw pictures together. Streaming video/audio would also be nice. Why not throw in SSL security too.

Boy if I can build the above I would be impressed.


Java,/client/server,course,chat,sockets,network

Free Java Client/Server Chat applet Software binaries and source

January 11th, 2006

I wrote PriadoChat client/server a long time ago to sell. Now I have decided to give it away for Free.

PriadoChat offers Multiple chatrooms, PriadoChat is an easily customizable chat engine for your website. It is powered by Java, but can be embedded into static HTML pages, PHP scripts, ASP scripts, JSP scripts, etc. The colors and server port are completely configurable.

Binaries

Source

This product is under the GPL License GPL License


Java,client/server, networking,chat, awt

Example Code:HWThreadedHash (Multithreaded Hashtable), a Multithreaded hash table will improve your applications performance

December 30th, 2005

I have written a multithreaded hash table framework. You can put multiple tasks to do work for you with a simple “put” with a key,Then when it completes you can do a “get” to return the data worked on. The “get” will block until that requested thread is finished working.
Read the rest of this entry »