62,623
社区成员
发帖
与我相关
我的任务
分享public String usb(){
try{
serverSocket=new ServerSocket(4567);
}catch (Exception e) {
e.printStackTrace();
System.out.println("服务存在了");
long ntime=System.currentTimeMillis();
long etime=0;
for(;;)//迟延1秒
{
etime=System.currentTimeMillis();
if(etime-ntime>1000)
{
break;
}
}
usb();//再次启动
}
System.out.println("服务器启动");
} public String usb() {
while (serverSocket == null) {
try {
serverSocket = new ServerSocket(4567);
} catch (Exception e) {
try {
Thread.sleep(2000);
} catch (Exception ex) {
}
}
}
System.out.println("服务器启动");
return "OK";
}