sedj
Programmer
- Aug 6, 2002
- 5,610
Hi,
have been getting a message :
SocketException - Connection reset by peer : JVM_recv in socket in input stream
which I cannot work out ... Have skinned my code back to two simple test classes - one which handles a ServerSocket, and passes Sockets to a thread, and one which opens a socket and trys to pass a string. Below is the code. The exception is thrown when the thread in class Test trys to create the BufferedReader ...
Curiously though, the error is intermittent.
Hope someone can help !
Regards,
Ben
/////////////the serversocket class /////////////
import java.net.*;
import java.io.*;
public class Test {
static Thread thread;
public static void main(String args[]) {
try {
ServerSocket ss = new ServerSocket(1234);
System.out.println("Listening on port ..."
while (true) {
processClient(ss.accept());
thread.start();
}
}
catch (IOException e) {
System.out.println(e.toString());
}
}
public static void processClient(Socket s) {
final Socket client = s;
System.out.println("Recieved Socket connection ..."
thread = new Thread(new Runnable() {
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String message = in.readLine();
System.out.println("Message was " +message);
}
catch (IOException e) {
System.out.println(e.toString());
}
}
});
}
}
/////////////////////////////////////////////////////
///////// and the Socket test class /////////////////
import java.net.*;
import java.io.*;
public class Test1 {
public static void main(String args[]) {
try {
Socket s = new Socket("localhost", 1234);
System.out.println("opened socket"
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
out.write("Hello"
System.out.println("sent message"
}
catch (IOException e) {
System.out.println(e.toString());
}
}
}
have been getting a message :
SocketException - Connection reset by peer : JVM_recv in socket in input stream
which I cannot work out ... Have skinned my code back to two simple test classes - one which handles a ServerSocket, and passes Sockets to a thread, and one which opens a socket and trys to pass a string. Below is the code. The exception is thrown when the thread in class Test trys to create the BufferedReader ...
Curiously though, the error is intermittent.
Hope someone can help !
Regards,
Ben
/////////////the serversocket class /////////////
import java.net.*;
import java.io.*;
public class Test {
static Thread thread;
public static void main(String args[]) {
try {
ServerSocket ss = new ServerSocket(1234);
System.out.println("Listening on port ..."
while (true) {
processClient(ss.accept());
thread.start();
}
}
catch (IOException e) {
System.out.println(e.toString());
}
}
public static void processClient(Socket s) {
final Socket client = s;
System.out.println("Recieved Socket connection ..."
thread = new Thread(new Runnable() {
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String message = in.readLine();
System.out.println("Message was " +message);
}
catch (IOException e) {
System.out.println(e.toString());
}
}
});
}
}
/////////////////////////////////////////////////////
///////// and the Socket test class /////////////////
import java.net.*;
import java.io.*;
public class Test1 {
public static void main(String args[]) {
try {
Socket s = new Socket("localhost", 1234);
System.out.println("opened socket"
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
out.write("Hello"
System.out.println("sent message"
}
catch (IOException e) {
System.out.println(e.toString());
}
}
}