我今天的问题如下:
我有一个网络连接,双方都必须发送命令(字节),但我的阅读器阻止了我的作者,看起来就是这样。如果我“禁用”我的读者(通过从源代码中删除读者),作者会按他应该的方式工作,但是当我的读者也在那里时,我的作者只做了一半的工作。
假设我的编写器必须以 15 秒的间隔发送一个命令,并留意传入的命令,这些命令必须由一个小字节块来回答。答案块已发送,但来自间隔的命令似乎被阻止。
这是我的来源:
protected String doInBackground(URL... params) {
try {
btw1 = (byte) sendbeg;
btw2 = (byte) w2;
btw3 = (byte) w3;
btw4 = (byte) w4;
btw5 = (byte) w5;
if (w5 == 79) {
btw6 = (byte) mins;
btw7 = (byte) seks;
btw8 = (byte) w6;
btw9 = (byte) sendend;
} else {
btw6 = (byte) w6;
btw7 = (byte) sendend;
}
SocketAddress sockaddr = new InetSocketAddress("192.168.0.7", 2001);
sock = new Socket();
int timeout = 1000; // 1000 millis = 1 second
sock.connect(sockaddr, timeout);
sock.setReuseAddress(true);
System.out.println(sock);
DataOutputStream dos = new DataOutputStream(
(OutputStream) sock.getOutputStream());
BufferedWriter wrtr = new BufferedWriter(
new OutputStreamWriter(dos), 300);
DataInputStream dis = new DataInputStream(sock.getInputStream());
BufferedReader rdr = new BufferedReader(new InputStreamReader(dis),
300);
getbyte((byte) btw1, (byte) btw2, (byte) btw3, (byte) btw4,
(byte) btw5, (byte) btw6, (byte) btw7, (byte) btw8,
(byte) btw9, (byte) btw10); //getbyte works fine, too. It's just there for putting the single bytes into an array.
System.out.println(btw.length);
dos.write(btw);
diny1 = (dis).read();
diny2 = (dis).read();
diny3 = (dis).read();
diny4 = (dis).read();
diny5 = (dis).read();
dinymin = (dis).read();
dinysek = (dis).read();
diny6 = (dis).read();
diny7 = (dis).read();
if (diny5 != 79) {
System.out.println("diny" + diny1 + " " + diny2 + " " + diny3
+ " " + diny4 + " " + diny5 + " " + dinymin + " "
+ dinysek);
} else {
if (diny7 != 5) {
diny6 = 0;
diny7 = 0;
}
System.out.println("diny" + diny1 + " " + diny2 + " " + diny3
+ " " + diny4 + " " + diny5 + " " + dinymin + " "
+ dinysek + " " + diny6 + " " + diny7);
}
dos.close();
wrtr.close();
dis.close();
rdr.close();
if (diny5 != 32) {
sendbeg = 3;
w2 = diny3;
w3 = diny2;
w4 = 48;
w5 = 32;
w6 = 11;
sendend = 5;
System.out.println(diny5 + " ^^ ");
doInBackground();
}
System.out.println("case 144-49-000.1" + context);
reccom(context);
sock.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("IO error " + e);
}
return "Done";
}
我的间隔源工作正常,因为如果阅读器不活动,它可以工作,所以我认为问题出在上面的代码中。请帮忙。