[1596] in java-interest
Broadcasting data via NetworkServer/NetworkClient
daemon@ATHENA.MIT.EDU (Robert Uomini)
Fri Sep 8 19:03:12 1995
Date: Fri, 8 Sep 1995 13:16:05 -0700
From: uomini@fractals.fractals.com (Robert Uomini)
To: java-interest@java.sun.com
Hi,
I'm trying to write an application, using the NetworkServer object,
which will periodically send some ASCII data to all NetworkClients
which are currently connected to the server. The code works fine
for one cleint talking to the server, but as soon as I start another
copy of the client I get an exception:
java.lang.IOException Connection reset by peer
at net.SocketInputStream.read(SocketInputStream.java:59)
at java.io.BufferedInputStream.fill(BufferedInputStream.java)
at java.io.BufferedInputStream.read(BufferedInputStream.java)
at StatsClient2.main(StatsClient2.java:28)
The server code looks like the following:
----------------------------Server-------------------------------------
import net.*;
import java.io.*;
class StatsServer
extends NetworkServer
implements Runnable
{
//
// Override super.serviceRequest()
//
static RandomAccessFile filestream;
String counter;
public synchronized void serviceRequest()
{
byte buf[] = new byte[300];
int n=0;
int c;
while (n == 0)
{
counter = filestream.readLine();
clientOutput.println(counter);
wait(3000);
filestream.seek(0);
clientOutput.flush();
}
}
//
// This is the class constructor
//
public StatsServer()
{
super();
}
public static void main (String args[])
{
String filename;
StatsServer ms[] = new StatsServer[1];
System.out.println("In main()!");
filename = "/opt/WWW/NCSA/httpd/cgi-bin/link_count";
filestream = new RandomAccessFile(filename, "r");
ms[0] = new StatsServer();
ms[0].startServer(8096);
}
}
and the client looks like:
----------------------------Client-------------------------------------
import net.*;
class StatsClient2 {
public static void main (String args[]) {
byte buf[] = new byte[300];
int n;
int c;
int i;
NetworkClient mc;
mc = new NetworkClient("www.fractals.com", 8096);
if ( mc == null )
{
System.out.println("Error connecting to server\n");
return;
}
mc.serverOutput.println("Hello from StatsClient2!");
mc.serverOutput.flush();
/*FAILS HERE*/ while ((n = mc.serverInput.read(buf, 0, buf.length)) >= 0) {
System.out.write(buf, 0, n);
}
mc.closeServer();
}
}
--------------------------------------------------------------------
Thanks for any help on this.
Bob
---
Robert Uomini
The Fractal Images Company (http://www.fractals.com)
Voice: 510-528-0258/800-548-0258
Fax: 510-528-0243
*******************************************************************************
* Buying or selling a home? Come visit the most comprehensive set of *
* residential real estate listings and related services on the Internet: *
* The FractalNet Real Estate Server, http://www.fractals.com/realestate.html *
*******************************************************************************
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com