当前位置:编程学习 > JAVA >>

求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相关
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,