我在android中使用标准java.net.Socket,在python中使用socket模块,当我在java中执行以下操作时:
sk = new Socket(addr, port);
input = new BufferedReader(new InputStreamReader(sk.getInputStream()));
output = new DataOutputStream(sk.getOutputStream());
...
output.writeUTF("connect 216082611046");
String message = input.readLine();
Log.wtf("cst", message);
并在python中遵循:
...
connection, addr = server.accept()
print "Received connection from", addr
s = connection.recv(1024)
...
connection.sendall(ip) #ip is some string there
我遇到了麻烦:java 接收到“connection.sendall(ip)”发送的消息,但只有当我关闭套接字时,但我需要让它保持活动状态并根据收到的数据继续消息传递。有没有办法在不关闭套接字的情况下获得答案?