JVM_recv in socket input stream error

I've opened a socket and I'm able to access the OutputStream. However, when I try to wrap a ObjectInputStream around the socket's InputStream, I get this error:

SocketException: Connection reset by peer: JVM_recv in socket input stream read.

What should I be looking for?

Larry

[312 byte] By [larrygriffith] at [2007-9-26 1:34:27]
# 1

I can only guess without seeing some code, but there are several things you must do for this to work:

You need to be connecting to a running server's ServerSocket before requesting the InputStream of your client's socket connection. Then, unless you are using standard Java classes, or RMI, your client and server must both have the class files for the types of objects you want to pass over the socket.

This should allow your application to work.

cajo at 2007-6-29 2:17:36 > top of Java-index,Archived Forums,Socket Programming...
# 2

> I can only guess without seeing some code, but there

> are several things you must do for this to work:

>

> You need to be connecting to a running server's

> ServerSocket before requesting the InputStream of your

> client's socket connection. Then, unless you are

There is indeed a ServerSocket. The accept call is being reached, but apparently it isn't accepting the connection. This is being tested on a single host simulating a network, so I don't think it's a network problem. I'll check further to see why the socket was opened on the client side but not on the server side, but right now I have to go put out some other fires (I redid my Solaris server last week and I'm now getting messages about what doesn't work.) I'll get back to you; thanks for your help. The program is much too large to post in its entirety, but if I can limit the range of where the error is I'll post the appropriate code.

> using standard Java classes, or RMI, your client and

> server must both have the class files for the types of

> objects you want to pass over the socket.

>

The classes are definitely at both ends (it's a single app that must run as a server on some hosts and as a client on others, depending on the data).

Larry

larrygriffith at 2007-6-29 2:17:36 > top of Java-index,Archived Forums,Socket Programming...
# 3

Here's the code which appears to be relevant, with some commentary on what happens when it is run. Large portions of (hopefully) irrelevant code have been snipped.

Client:

COMMENT: Start a server using RMI. This appears to

COMMENT: succeed, since a message printed by this

COMMENT: server does appear.

try {

DistLrnRemoteData dlrd =

(DistLrnRemoteData)Naming.lookup(

"//"+personHost+

"/DistanceLearningData");

dlrd.activatePersonServer();// Get server going

}

catch (Exception e) {

System.err.println(e);

COMMENT: This line is NOT printed, so apparently

COMMENT: there is no Exception.

System.err.println("Unable to initialize remote Person server");

e.printStackTrace(System.err);

}

Person result = new Person();

int count = 10;

boolean opened = false;

Socket gpsocket = null;

while (!opened) {

try {

COMMENT: The client attempts to open the socket

COMMENT: here. The server never seems to accept it,

COMMENT: but this call appears to succeed. There is

COMMENT: no Exception. The server is running code

COMMENT: from the class RemoteDataServer, so the

COMMENT: port should be the same. The testing was

COMMENT: done with a single host acting as both

COMMENT: client and server, so there isn't any firewall

COMMENT: or network outage problem.

gpsocket = new Socket(personHost,

RemoteDataServer.personReadPort);

opened = true;

}

catch (IOException ioe) {

count--;

if (count <= 0) {

COMMENT: This line is NOT printed, so apparently there

COMMENT: is no IOException when the Socket is

COMMENT: created. Nor does an UnknownHostException

COMMENT: or SecurityException stop the program.

System.err.println(ioe);

ioe.printStackTrace(System.err);

result = null;

return result;

}

try {

Thread.sleep(1000);

}

catch (InterruptedException ie) {

System.err.println(ie);

ie.printStackTrace(System.err);

}

}

}

// Read the serialized object

try {

COMMENT: No problem with the next line, which attempts

COMMENT: to access the OutputStream of the socket.

MyStringWriter msw = new MyStringWriter(

gpsocket.getOutputStream());

COMMENT: The next line causes the message.

ObjectInputStream ois =

new ObjectInputStream(gpsocket.getInputStream());

msw.write(personRealName);

// Now read the resulting Person.

try {

result = (Person)(ois.readObject());

}

catch (ClassNotFoundException cnfe) {

System.err.println(cnfe);

cnfe.printStackTrace(System.err);

System.exit(4);

}

}

catch (IOException ioe) {

System.err.println(ioe);

ioe.printStackTrace(System.err);

result = null;

}

Server:

public void activateFocusServer() throws java.rmi.RemoteException {

String [] cmd = new String[2];

cmd[0] = new String("java");

cmd[1] = new String("RemoteDataServer");

try {

COMMENT: FORTE's Output window shows a message

COMMENT: from this process

Process dbserver =

Runtime.getRuntime().exec(cmd); // Server will self-destruct

// after a timeout period

}

catch (IOException ioe) {

COMMENT: This message is never printed

System.err.println(ioe);

ioe.printStackTrace(System.err);

}

}

RemoteDataServer:

public RemoteDataServer() {

try {

...many different servers started here...

ServerSocket PersonReadSocket = new ServerSocket(personReadPort);

PersonReadListener prl = new PersonReadListener(PersonReadSocket);

prl.start();

....

catch (IOException ioe) {

COMMENT: This message is never printed.

System.err.println(ioe);

ioe.printStackTrace(System.err);

}

COMMENT: PersonReadListener is an inner class:

class PersonReadListener extends java.lang.Thread {

private Thread BaseThread;

private ServerSocket theSocket;

/** Creates an object to listen for PersonRead requests

* @param ss The server socket to listen with

*/

public PersonReadListener(ServerSocket ss) {

theSocket = ss;

}

/** Initializes the thread to listen for PersonRead requests

*/

public void start() {

BaseThread = new Thread(this);

BaseThread.start();

}

/** The code for the server to listen for PersonRead requests

*/

public void run() {

while(true) {

try {

COMMENT: This code doesn't have access to System.err

COMMENT: so a file is created to print debugging output

PrintWriter debug = new PrintWriter(new FileWriter("person.debug"));

COMMENT: The next line IS printed, so the server gets

COMMENT: this far.

debug.println("Waiting for connection for person's name");

debug.close();

PersonReadClientConnection someone =

new PersonReadClientConnection(theSocket.accept());

COMMENT: If the previous "debug.close" line is

COMMENT: commented out and the next two lines are

COMMENT: uncommented, the next line is NOT

COMMENT: printed, so apparently the accept nevers

COMMENT: happens! Why does the accept fail, but

COMMENT: the client's socket creation succeed?

// debug.println("Accepted a connection");

// debug.close();

someone.start();

}

catch (IOException ioe) {

COMMENT: These lines are NOT printed

System.err.println(ioe);

ioe.printStackTrace(System.err);

}

larrygriffith at 2007-6-29 2:17:36 > top of Java-index,Archived Forums,Socket Programming...