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

Code Example: Data Transfer Object DTO or Data Beans

January 17th, 2006

When you are implementing you jdbc layer, you need a solid way to create Data Transfer Objects (DTO’s) or Data Beans . This is the way I implement this.
Read the rest of this entry »

Java Software Development Kit

January 10th, 2006

Sun Microsystem’s Java Developers Kit (SDK) is a set of tools that are needed to develop Java programs and applets. The latest SDK can be found at: http://www.javasoft.com/. The JDK contains:
• javac – Java compiler
• java – Java Interpreter
• jdb – Java debugger
• appletviewer – Java applet viewer
• javadoc – API doc generator
• applet API documentation
• Java Programming guide

History

January 10th, 2006

The Java language was used in several projects while it was being designed. Originally Java was intended for use in programming consumer devices. However, it turned out to be a great language for programming for the Internet.
Read the rest of this entry »