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
Posted in Client/Server, Code Examples, Course, multithreading | 3 Comments »
March 20th, 2006
This simple code 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,sockets,network
Posted in Client/Server, Code Examples | No Comments »
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
Posted in Client/Server, Code Examples, Course, Swing, multithreading | 4 Comments »
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
Posted in Client/Server, Code Examples, Course, Swing, multithreading | 4 Comments »
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
Posted in Client/Server, Code Examples, Course, Swing, multithreading | 4 Comments »