[2532] in java-interest

home help back first fref pref prev next nref lref last post

Re: client-server using ONLY java.net.*

daemon@ATHENA.MIT.EDU (Thomas Ball)
Wed Oct 4 02:24:27 1995

Date: Mon, 2 Oct 1995 15:26:28 -0700
From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
To: nataraj@cat.syr.edu
Cc: java-interest@java.Eng.Sun.COM

>  I am trying out the java.net classes. (Socket/ServerSocket,...)
>  >From the available documentation, I am not able to figure out the
>  relation between SocketImpl and the Socket/ServerSocket ...
>  Is there any simple/sample code out there, which uses ONLY java.net.*
>  classes and none of sun.java....? I want to try out only with
>  the java API classes. 

The following connects a client and a server without using any sun.net 
classes.  To make it useful, you need some sort of protocol such as a
simple command/response one.  If you are already using two pipes for
inter-app communication, the same protocol will work.

Server side:

    ServerSocket socket = new ServerSocket(port_number, 10);
    if (i >= 10) {
	error("**Failed to create port\n");
	return;
    }

    Socket connection = socket.accept();
    DataInputStream in = new DataInputStream(
	new BufferedInputStream(cmdSocket.getInputStream()));
    DataOutputStream out = new DataOutputStream(
	new BufferedOutputStream(cmdSocket.getOutputStream()));

Client side:

    Socket socket = new Socket(host, port_number);
    in = new DataInputStream(new
	BufferedInputStream(socket.getInputStream()));
    out = new DataOutputStream(new
	BufferedOutputStream(socket.getOutputStream()));

Tom Ball
Java Products Group

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post