Java从Python服务器-套接字接收消息
我尝试使用套接字从python接收消息。我的客户机是java代码 我编写代码是为了尝试获取从python发送的所有数据(只是为了了解它是如何工作的),但我什么都没有得到。 我的代码: Python服务器:Java从Python服务器-套接字接收消息,java,python,sockets,Java,Python,Sockets,我尝试使用套接字从python接收消息。我的客户机是java代码 我编写代码是为了尝试获取从python发送的所有数据(只是为了了解它是如何工作的),但我什么都没有得到。 我的代码: Python服务器: import socket, time HOST = '10.0.0.2' PORT = 12345 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((HOST, PORT)) server.li
import socket, time
HOST = '10.0.0.2'
PORT = 12345
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen()
client, address = server.accept()
print('Connected by', address)
while True:
client.send(b"Hello Java")
time.sleep(0.5)
我的java代码:
try {
socket = new Socket("10.0.0.2", 12345); // Connect to server
PrintWriter out = new PrintWriter(socket.getOutputStream()); // Get output
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); // Get the input
while (true) {
System.out.println(in.readLine()); // It does not print anything
}
} catch (Exception e) {
System.out.println("Error");
e.printStackTrace();
}
如何从python接收消息?