0

I made a server python with the next code (i think the rest of the code isn't necessary):

while 1:
 data = conn.recv(BUFFER_SIZE)
 if not data: break
 print "received data:", data
 conn.send(data+'\r\n')
conn.close()

and when i try to received the echo with a Java client, i get a strange message when printing on console:

Mensaje recibido = java.io.DataInputStream@1cf2a0ef

At server point, I'm receiving good the message: Hola Mundo.

The code in Java is:

 DataInputStream ims;
 String data;
 s = new Socket(HOST,PORT);
 oms = new DataOutputStream(s.getOutputStream());
 ims = new DataInputStream(s.getInputStream());
 oms.writeUTF(ms);
 ims.read();
 data = ims.toString();
 oms.close();
 ims.close();
 s.close();
 return data;

I think that ims.toString() is probably wrong.

asked Apr 23, 2015 at 16:14

2 Answers 2

1

What you need is to assign data to a string read from the stream:

data=ims.readUTF();

the toString() method in the stream just returns a representation of the object id, it's meaningless.

See http://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readUTF()

answered Apr 23, 2015 at 16:18
Sign up to request clarification or add additional context in comments.

Comments

1

You are correct that ims.toString is wrong. If python is sending a UTF-8 string you could use ims.readUTF().

answered Apr 23, 2015 at 16:18

2 Comments

I thought that readUTF() don't return the string, i didn't read the documentation of Java, thank you!
It's working, i don't need more help at the moment hahaha thanks!

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.