我的 java 客户端无法与我的 python 服务器一起使用

My java client doesn't work with my python server

我正在构建一个 java 客户端和一个 python 服务器,当我 运行 它们使用匹配的语言 clients/server 时它们都工作正常,但是当我运行 java 客户端与 python 服务器套接字连接,但每当我尝试读取从 python 服务器发送的数据时 java 终端卡住

这可能是一个缓冲问题,因为每当我使用从 python 接收到的数据调用缓冲区时,终端就会卡在所说的行中并且不会让步。

这是 python 服务器:

import socket
import pyautogui
def main():
    HOST = ""              # Endereco IP do Servidor
    PORT = 1234            # Porta que o Servidor esta
    tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    orig = (HOST, PORT)
    tcp.bind(orig)
    tcp.listen(1)
    while True:
        con, cliente = tcp.accept()
        print ('Concetado por', cliente)
        cone="Conectado".encode()
        con.send(cone)
        while True:
            msg = con.recv(1024).decode()
            if msg[0]=="/" :
                cmsg=''
                for i in range(1,len(msg)):
                    cmsg+=msg[i]
                exec(cmsg)
            if not msg: break
            print (cliente, msg)
        print ("Finalizando conexao do cliente", cliente)
        con.close()
main()

这是Java:

import java.io.*;
import java.net.*;
import java.util.Scanner;

public class MyClient {
    public static void main(String[] args) {

        try {
            Socket soc = new Socket("localhost", 1234);
            DataOutputStream dout = new DataOutputStream(soc.getOutputStream());
            OutputStreamWriter osw = new OutputStreamWriter(dout);
            BufferedWriter bw = new BufferedWriter(osw);
            InputStream is = soc.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            System.out.println("Here");
            System.out.println(br.readLine());
            System.out.println("Here2");
            Scanner scanner = new Scanner(System.in);
            while (!(bw.readLine().equals("exit"))) {
                System.out.println(br.readLine());
                String input = scanner.nextLine();
                bw.write(input);
                bw.flush();
            }
            dout.close();
            soc.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

所以我实际上发现了问题所在,问题出在缓冲区上,它显然不明白线路结束了,所以为了解决这个问题,我只需要发送 "Conectado\n'