62,614
社区成员
发帖
与我相关
我的任务
分享
/**
* StartClient
*
*/
class StartClient implements Runnable {
public void run() {
try {
Socket socket = null;
boolean flag = true;
while (flag) {
try {
socket = new Socket("127.0.0.1", 10003);
} catch (ConnectException ex) {
ex.printStackTrace();
}
if (socket != null) {
flag = false;
}
}
// 用于获取服务端传输来的信息
BufferedReader buff = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Thread t = null;
String[] arr = null;
while (true) {
String str = buff.readLine(); // 运行时出错行,报的异常如题
if (str != null) {
arr = str.split(" ");
}
if (map.containsKey(arr[0])) {
t = new Thread(new ClientNet(arr));
t.start();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}