• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket Exception: Connection Reset by Peer  RSS feed

 
Jay Crosley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with a pong game in which a server and client connect and then send model back and forth. I'm trying to connect to another computer on my network (it works fine when I just connect to myself). The computers clearly are connecting because I'm getting my "connection accepted" println statement where the connection happens, and printing out the client ip address, which is the right one. But nothing is changing on the screen and I'm getting the following error : "Trying to send model: java.net.SocketException: Connection reset by peer: socket write error." Anyone know why this is happening? I've posted the NetworkServer code that throws the error below. It's thrown at the sendModel method.

import java.net.*;
import java.io.*;

public class NetworkServer implements Runnable {
private Socket client;
private PongModel model;
private PrintStream out;
private InputStream in;
private ObjectOutputStream oos;

public NetworkServer(Socket client, PongModel model) {
this.client = client;
this.model = model;
model.setClient(this);
try {
in = client.getInputStream();
out = new PrintStream(client.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}

public void run() {
try {
InputStream in = client.getInputStream();
while (true) {
ObjectInputStream ois = new ObjectInputStream(in);
Paddle rightPaddle = (Paddle)ois.readObject();
model.updatePaddle(rightPaddle);
}
} catch (Exception e) {
System.out.println("Updating right paddle from clienat: " + e);
}
}

public void sendModel() {
try {
ObjectOutputStream oos = new ObjectOutputStream(client.getOutputStream());
oos.writeObject(model);
oos.flush();
} catch (Exception e) {
System.out.println("Trying to send model: " + e);
}
}
}
 
Jay Crosley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so I changed the port I'm using from 500 to 7575 and suddenly it worked, but it was working with 500 yesterday, which is what confused me about why it wasn't working today. Does anyone know what happened to port 500? Do I have to clear the port after I use it or something?
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this class trying to address that question, it has a lot of useful details but I never got around to testing it or getting the range selector matched to the randomizer because I was using two different randomizers that had different calling signatures. Additionally, I became motionless on how to negotiate port numbers across to machines without having a default port prior to the negotiation. People will say lowest default port is 1024 but it is actually 49152 through 65535 - that's in here.

 
Jay Crosley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply, that might be useful in the future. However, after hours of trying to discover what the "bug" is, I found out that the game connects when I run it in Dr. Java on both machines, but not when I run it in Eclipse on one and Dr. Java on the other. I don't have Eclipse on both, so I can't test that. I don't know why this would be the case, except for one idea. I think it's possible that since Dr. Java is loaded on the other machine, I was given the option to "unblock" it from the internet, whereas the firewall is blocking information from eclipse, a program it doesn't recognize. Is that possible?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!