Name: diC59631 Date: 05/22/98
1. (a) java SocketReader 1234
(b) java SocketWriter your_host 1234
2. Code can not fit in here
I will send you e-mail including the code
------------------------------------------
Sat May 2 22:36:26 PDT 1998
Additional info from user: (transferred from Incident # 29556):
Path: engnews3.Eng.Sun.COM!news
From: ###@###.###
Newsgroups: fp.bugs
Subject: Unknown bug report
Date: 2 May 1998 12:33:55 -0700
Organization: Sun Microsystems Inc., Mountain View, CA
Lines: 137
Sender: ###@###.###
Approved: ###@###.###
Distribution: local
Message-ID: <###@###.###>
NNTP-Posting-Host: engnews3.eng.sun.com
To: ###@###.###
From: ###@###.### (Shauh-Wen Ma)
This does not look like form output to me.
Hi,
I just enter a bug report on the bug-report page, but the
textarea just too small to fit the program, here is the problem
and program.
The setTcpNoDelay method seems does not work, I have to use
setSoTimeout (1) to simulate a non-blocing socket.
Here is the progrm:
Just compile the SocketReader.java and SocketWriter.java
And
(1) java SocketReader 1234
(2) java SocketWriter host 1234
Then you can see the Reader is "blocked".
THX
Shauh-Wen Ma
###@###.###
=============================================================================
SocketReader.java
=============================================================================
import java.net.*;
import java.io.*;
class SocketReader
{
public static void main (String args [])
{
if (args.length < 1)
{
System.out.println ("USAGE: java SocketReader port");
System.exit (-1);
}
String portStr = new String (args [0]);
try
{
int port = Integer.parseInt (portStr);
ServerSocket readServer = new ServerSocket (port);
Socket connection = readServer.accept ();
connection.setTcpNoDelay (true);
InputStream inStream = connection.getInputStream ();
BufferedInputStream isr =
new BufferedInputStream (inStream);
boolean done = false;
byte bb[] = new byte[2048];
int rBytes = 0;
while (true)
{
rBytes = isr.read (bb, 0, 2048);
System.out.println ("rBytes == " + rBytes);
if (rBytes < 0) break;
String line = new String (bb, 0, rBytes);
System.out.print ("line == " + line);
if (line.startsWith ("QUIT"))
{
break;
}
}
readServer.close ();
}
catch (Exception e)
{
e.printStackTrace ();
System.exit (-1);
}
}
}
==============================================================================
SocketWriter.java
==============================================================================
import java.net.*;
import java.io.*;
class SocketWriter
{
public static void main (String args [])
{
if (args.length < 2)
{
System.out.println ("USAGE: " +
"java SocketWriter hostname port");
System.exit (-1);
}
String host = new String (args [0]);
String portStr = new String (args [1]);
try
{
int port = Integer.parseInt (portStr);
Socket outSock = new Socket (host, port);
System.out.println ("Socket created to " + host);
OutputStream outStream = outSock.getOutputStream ();
PrintWriter ps = new PrintWriter (outStream, true);
InputStreamReader isr =
new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
boolean done = false;
System.out.println ("Type sentence to send. " +
"Type 'exit' to quit.");
while (! done)
{
String line = br.readLine ();
if (! line.startsWith ("exit"))
{
ps.println (line);
}
else
{
ps.println ("QUIT");
done = true;
}
}
outSock.close ();
}
catch (Exception e)
{
e.printStackTrace ();
System.exit (-1);
}
}
}
=============================================================================
(Review ID: 29493)
======================================================================