⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketopener.java

📁 piweurrrrq i o fhsadhfka fd dskajc zxkjcnkjsahc
💻 JAVA
字号:
/* * Copyright (c) 2000 Lyrisoft Solutions, Inc. * Used by permission * * Based on code by Dan Bastone (dan@gibinc.com). */package com.lyrisoft.chat.server.local;import java.io.*;import java.net.*;public class SocketOpener implements Runnable {    ISocketFactory socketFactory;    Socket socket;    IOException ioexception;        public SocketOpener(String host, int port) {        socketFactory = new SocketFactory(host, port);    }    public void run() {        try {            socket = socketFactory.makeSocket();            return;        }        catch (IOException e) {            ioexception = e;        }    }        public Socket makeSocket(long timeout) throws IOException {        socket = null;        ioexception = null;        Thread socketThread = new Thread(this, "MakeSocketThread");        socketThread.start();        try {            socketThread.join(timeout);        }        catch (InterruptedException e) {}        if ( socketThread.isAlive() ) {            socketThread.stop();        }        if (ioexception != null) {            throw ioexception;        }        if (socket == null) {            throw new IOException ("Operation timed out");        }        return socket;    }}interface ISocketFactory {    Socket makeSocket() throws IOException;}class SocketFactory implements ISocketFactory {    String _host;    int _port;    public SocketFactory(String host, int port) {        _host = host;        _port = port;    }    public Socket makeSocket() throws IOException {        return new Socket(_host, _port);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -