求java牛人们给看看代码,想弄个尝试连接,找到个代码看不明白
public class Client extends Thread {private boolean connect() {
boolean ret = false;
try {
if (socket == null) {
int port = 555
socket = new Socket(serverip, port);
socket.setTcpNoDelay(true);
socket.setSoLinger(true, 1);
socket.setSoTimeout(0);
socket.setKeepAlive(false);
socket.setReceiveBufferSize(10240);
log.info("[connect to server ok port]: " + socket.getLocalPort());
isConnected = true;
}
} catch (Exception ex) {
ret = false;
log.info("[connect to server error]:\r\n" + ex.getMessage());
}
return ret;
}
public void run() {
//检查心跳
while (!isShutdown) {
try {
if (socket == null) {
if (!connect()) {
isConnected = false;
Thread.sleep(5000);
continue;
} else {
//登录成功
}
}
..................
} java
补充:Java , Java相关