问题描述
我有一个正在运行的Java套接字服务器实例,我想使用python从该实例接收和发送数据。我也有Java等效代码来执行此任务,但是用Python重写相同的过程无法完成任务,并且服务器超时后连接也会中断。
<tr v-for="(input,index) in inputs">
<input :disabled="input.disabled">
...
</tr>
编写的Python代码:
public class ctakesSocketClient {
public static void main(String[] args) throws UnknownHostException,IOException,ClassNotFoundException,InterruptedException{
Socket socket = null;
ObjectOutputStream oos = null;
DataInputStream ois = null;
socket = new Socket("10.2.1.21",6700);
System.out.println("Connected");
String string = "Blood Pressure";
System.out.println("Sending request to Socket Server");
OutputStream oStream = socket.getOutputStream();
oStream.write(string.getBytes());
socket.shutdownOutput();
long started = System.currentTimeMillis();
InputStream iStream = socket.getInputStream();
byte[] bytes = new byte[1024];
int numRead = 0;
List<Byte> lstBytes = new ArrayList<>();
while((numRead = iStream.read(bytes)) > 0) {
for (int i = 0; i < numRead; i++) {
lstBytes.add(bytes[i]);
}
}
byte[] result = new byte[lstBytes.size()];
for(int i = 0; i < lstBytes.size(); i++) {
result[i] = lstBytes.get(i);
}
long finished = System.currentTimeMillis();
System.out.println("Message: " + new String(result));
System.out.println("Time taken: " + ((finished-started)/1000) + " minutes");
socket.close();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)