Click to See Complete Forum and Search --> : Client and server program on same system -- Java


Sawdusty
04-01-2002, 01:59 PM
Hello,

I've discovered in my networking class that I have to do some client/server programming in java. I was wondering if and how the best way I could run the client and server on the same (linux, of course) compter. Is it possible to create both using localhost as the hostname, somehow?

I haven't even tried this, but I want something that would work like this... would it work?:

Socket clientSocket = new Socket("localhost", 6789);

and in the server:

ServerSocket welcomeSocket = new ServerSocket(6789);

Can I do stuff like that? Even in UDP?

Thanks lots,
Dusty

kmj
04-01-2002, 02:17 PM
you should have no problem running a client and server on the same system, but the client and server must use different ports. After all, only one app at a time can use a port.

Strike
04-01-2002, 03:02 PM
http://pont.net/socket/java/

You can actually use ServerSocket for the server and Socket for the client. The above link has very simple examples you can build off of.