level 9
public class Socket_Thread implements Runnable{
String IP_str,liaotian;
int duankou_str;
BufferedReader Buffer_is;
OutputStream os;
Socket socket;
//构造方法,取得IP地址,端口号,显示面板
public Socket_Thread(String iP_str, int duankou_str,TextView show_xinxi) {
this.IP_str=iP_str;
this.duankou_str=duankou_str;
}
@Override
public void run() {
try {
socket=new Socket(IP_str,duankou_str);
socket.setSoTimeout(5000);
//取得socket的输入流
Buffer_is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//取得socket的输出流
os = socket.getOutputStream();
//测试连接
os.write("连接成功。。。。\n".getBytes("GBK"));
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (true) {
try {
liaotian+=("\n"+Buffer_is.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
2013年10月26日 04点10分