0

I am having an issue with Java ServerSocket and Python where I have an multithreaded echo server (Written in Java) that can communicate with multiple java clients. This all works fine.

When I try to connect with a python client, the python client can receive data from the server but when it sends data the server appears never to receive it.

I can only see the data at the server when i try to send 500K + bytes. While i can now see the data its is incomplete and out of sync.

I tested the follwing example code and it works fine with python: http://norwied.wordpress.com/2012/04/17/how-to-connect-a-python-client-to-java-server-with-tcp-sockets/

The only real difference is that in the code from the link it uses:

BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream(),

Where as in my server I use:

streamOut = new DataOutputStream(new BufferedOutputStream(s.getOutputStream())); 
streamIn = new DataInputStream(new BufferedInputStream(socket.getInputStream()));

Could this be causing the issue ?

asked Sep 20, 2013 at 13:15

2 Answers 2

1

In your code example, the PrintWriter was set to autoflush. This means that when println() is called, the buffer will be flushed and, consequently, sent to the network. You however, use a BufferedOutputStream and probably forgot to flush() your OutputStream.

answered Sep 20, 2013 at 13:29
Sign up to request clarification or add additional context in comments.

3 Comments

Yea, it seems to be that issue but there is no way that I have found at the moment to flush the buffer in python. It seems to rely on a EOL to send. Is there an alternative way to make it flush ?
Is there a method flush()?
unfortunately not. We have re coded into java all is good now =)
0

I think your python client isn't flushing the stream, which is why java server only gets data after the buffer on the client is full.

answered Sep 20, 2013 at 13:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.