Hi all,
EDIT: i've solved it
: i forgot to add to receive data from the server, and the server was sending data, so it kinda crashed because of that
i'm working on a game, and i'm using sockets to communicate with the clients. The server is built in python, and the client is currently being built in Java.
I've used the same python server to communicate with flash sockets, and it worked fine. But since i use Java, python always throws me an error:
Code:
File "/home/tvd/Desktop/python/client/clientsocket.py", line 59, in run
data = self.sock.recv(4096)
socket.error: (104, 'Connection reset by peer')
The error occures when i send data to the server: it receives the data (it prints it curently), and then it shows this error.
I've been searching the web for a while, but i can't seem to find a sollution. Here's my java code:
Code:
import java.net.Socket;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class ClientSocket {
private Socket core;
private BufferedReader in;
private PrintWriter out;
public ClientSocket(String host, int port){
try{
this.core = new Socket(host, port);
this.listen();
} catch(IOException e){
System.err.println("Error occured in ClientSocket():\r\n"+e.getMessage());
System.exit(1);
}
}
public static void main(String[] args){
ClientSocket sock = new ClientSocket("localhost", 8888);
sock.send("Hello");
sock.close();
}
private void listen() throws IOException{
try{
this.out = new PrintWriter(this.core.getOutputStream(), true);
this.in = new BufferedReader(new InputStreamReader(this.core.getInputStream()));
} catch(IOException e){
System.err.println("Error occured in listen():\r\n"+e.getMessage());
System.exit(1);
}
}
public void send(String value){
this.out.println(value);
}
private void close(){
try{
this.core.close();
}catch(IOException e){
System.out.println("Error occured in close():\r\n"+e.getMessage());
System.exit(1);
}
}
}
As i use the same server, i assume the problem is located in Java. This is just a basic code for testing how servers work in Java, so if there are some major errors, please let me know.
Thanks in advance,
UnrealEd