Current location: Hot Scripts Forums » Programming Languages » Everything Java » Sockets: Java client, python server problem

Sockets: Java client, python server problem

Reply
  #1  
Old 12-17-06, 04:49 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community VIP
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 2,724
Thanks: 0
Thanked 0 Times in 0 Posts
[solved]Sockets: Java client, python server problem

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
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

If you want to add me on any IM, pm me first

Last edited by UnrealEd; 12-17-06 at 05:28 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
soccet client server gagarin_uri C/C++ 1 11-15-06 05:09 PM
CGI Script Problem on new Linux server sujata_ghosh Perl 2 11-14-06 12:41 AM
programming tutor sought: Java and Windows 2000 Server usallsys Job Offers & Assistance 0 01-13-06 02:08 PM
Local Server - Dreamweaver MX 2004 problem mcrob PHP 1 10-27-05 02:34 PM
Please Help ! sweetgurl Everything Java 2 04-13-04 12:57 PM


All times are GMT -5. The time now is 02:01 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)