// 发送信息
byteout = new PrintStream(socket.getOutputStream());
byteout.write(sendStart.data);
System.out.println(s);
sleep(500);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (r == 3) {
ShowDialog("服务器无响应");
// 业务主线程,负责接收服务器端的消息
class receive extends Thread {
public void run() {
try {
while (socket.isConnected()) {
in = socket.getInputStream();
in.read(content);
// if (收到数据) {
flag = false;
//这个睡眠是为了给时间让send看到标记变量已改变
sleep(1000);
byteout.close();
socket.close();
。。。。。。。。。。。。。。。
} catch (Exception ex) {
ex.printStackTrace();
第二种方法:
package com.test;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("1111111111");
// 业务主线程,负责接收服务器端的消息
class receive extends Thread {
private Thread subThread;
public receive(Thread thread) {
subThread = thread;
public void run() {
// 使SEND线程结束
try {
sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
subThread.suspend();
System.out.println("关闭");