我做了一个python服务器,可以用socket从java客户端接收字符串消息,现在我想从python服务器向java客户端发送字符串消息请帮帮我,我是java新手,请帮帮我。!
以下是java代码:public client(String address, int port) throws IOException {
// establish a connection
try {
socket = new Socket(address, port);
System.out.println("Connected");
// takes input from terminal
input = new DataInputStream(System.in);
// sends output to the socket
out = new DataOutputStream(socket.getOutputStream());
System.out.print(input);
} catch(UnknownHostException u) {
System.out.println(u);
}
// string to read message from input
String line = "";
// keep reading until "Over" is input
while (!line.equals("Over")) {
try {
line = br.readLine();
out.writeUTF(line);
} catch(IOException i) {
System.out.println(i);
}
}
// close the connection
try {
input.close();
out.close();
socket.close();
} catch(IOException i) {
System.out.println(i);
}
}
public static void main(String args[]) throws IOException {
client client = new client("127.0.0.1", 12345);
}
下面是python服务器代码,用于向java客户端发送消息:
^{pr2}$
#在