I need to send a message from a java client program to a python server program.
Here is my code:
Java client:
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
public class Client {
public static void main(String[] args) throws IOException {
// need host and port, we want to connect to the ServerSocket at port 7777
Socket socket = new Socket("localhost", 7777);
System.out.println("Connected!");
// get the output stream from the socket.
OutputStream outputStream = socket.getOutputStream();
// create a data output stream from the output stream so we can send data through it
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
System.out.println("Sending string to the ServerSocket");
// write the message we want to send
dataOutputStream.writeUTF("Hello from the other side!");
dataOutputStream.flush(); // send the message
dataOutputStream.close(); // close the output stream when we're done.
System.out.println("Closing socket and terminating program.");
socket.close();
}
}
Python server:
from multiprocessing.connection import Listener
address = ('localhost',7777)
while True:
with Listener(address, authkey=None) as listener
with listener.accept() as conn:
print(conn.recv())
When I try to execute this, I get the following error in Python:
OSError: got end of file during message
What am I doing wrong?