[2093] in java-interest

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

re:Client/Server question... (already have applets/applications up

daemon@ATHENA.MIT.EDU (andrew (a.) francis)
Sun Sep 24 18:57:08 1995

Date:  Sun, 24 Sep 1995 16:00:00 -0400 
From: "andrew (a.) francis" <andrewfr@bnr.ca>
To: devjava@gscorp.com
Cc: java-interest@java.sun.com

In message "Client/Server question... (already have applets/applications up and running)", you write:

> I have some pretty neat client-server applets/applications running  
> now but I have one question for anyone who might possibly know the  
> answer.

> I can instanciate a NetworkClient and have it talk to a NetworkServer  
> instance.  However the server can't talk back to the client at all...  
> at least I can't figure out how to do it. 

[lines deleted]

A while back, I wrote this code fragment to try out NetworkServer.
When a client connects, it prints a message and echos back messages
from the client. I used telnet to test out the programme. Since I have 
not looked at the new API, I don't know if the Socket class has changed.

class MyNetworkServer extends NetworkServer
{

//  We have to override serviceRequest to do something useful with 
//  this method

      public void serviceRequest()
      {
           int count;
           byte message[] = {'W','e','l','c','o','m','e',' ','t','o',' ','m','y',
                             ' ','t','o','y',' ','s','e','r','v','e','r','\n'};

           byte buffer[] = new byte[80]; 

//  write a welcome message

           clientSocket.outputStream.write(message);

           while (true)
           {
                 clientSocket.inputStream.read(buffer);
                 System.out.write(buffer); 
                 clientSocket.outputStream.write(buffer);
           }
      }
}

Cheers,
Andrew

-
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