Home TCP Socket communication Java - Python
Reply: 0

TCP Socket communication Java - Python

user1532 Published in July 16, 2018, 6:36 am

I want to transmit an integer number throught a socket. I have a python script that open a socket and wait for requests, in the other side there is a Java servlet that send a request at this socket to obtain a value.

All the communication works well the problem is that the value obtained from java cause a EOFexception. I've tried some convertion and formats in the python script (I'm not expert of this language) but nothing works.

Instead, if I use in python a echo socket, picking all that socket receive and send back to java, all working fine.

But I need to send a simple value.

The following is the portion of code that I use, I've tried with float, this is with a String value:

[Python socket related istructions]

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = sock.accept()

[Python echo socket working]

data = connection.recv(16)
if data:

instead I want to do:

[Python return a example value]


That working if I send request from a client like Hercules but cause a EOFexception in Java

[Java Servlet - send request]

socket = new Socket(address, port);
dataInputStream = new DataInputStream(socket.getInputStream());
String content = dataInputStream.readUTF(); //EOFexception
Destination.value = content;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.329014 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO