Example Code: A simple Socket example

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

Leave a Comment