首先我想承认是的。。。我对这个项目的理解有点过头了,而且我对Python和Java的有限知识几乎一筹莫展。在
目标:使用Java中的input SocketServer通过TCP将数据输出到另一台机器上的Python客户机。在
问题:在我把Python客户机移到另一台计算机之前,代码运行得很好。没有错误,但是服务器从不打印出客户端连接的消息,这意味着上一行尚未执行。在
JAVA服务器:import java.net.ServerSocket;
import java.net.Socket;
import java.io.InputStreamReader;
import java.io.DataOutputStream;
import java.io.*;
import java.util.Scanner;
public class theServer {
public static void main(String[] args) throws IOException {
{
String godeep;
int portNumber = 4000;
String fromclient;
ServerSocket Server = new ServerSocket(4000);
System.out.println("TCPServer Waiting for client on port 5000");
while (true) {
Socket connected = Server.accept();
System.out.println(" THE CLIENT" + " "
+ connected.getInetAddress() + ":"
+ connected.getPort() + " IS CONNECTED ");
DataOutputStream outToPython = new DataOutputStream(
connected.getOutputStream());
while (true) {
Scanner keyboardInput = new Scanner(System.in);
godeep= keyboardInput.nextLine();
if (godeep.equals("q")) {
outToPython.writeBytes("dothatclose");
connected.close();
break;
}
outToPython.writeBytes(godeep);
}
}
}
}
}
PYTHON客户端:
^{pr2}$
这是我第一次发帖,所以我不太熟悉其他信息的惯例。是的,我知道我的变量名和诸如此类的名字都很奇怪,但我对这样做的希望很渺茫,所以我并不太在意这些。尽管这些建议与这个问题无关,但请随意给出任何其他关于如何改进我的代码的建议,因为我真的不知道我在做什么。谢谢。在