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

📄 tcpconnection.java

📁 短信发送
💻 JAVA
字号:
/**
 * Created at Nov 22, 2008
 */
package com.jdev.net.connector;

import com.jdev.net.queue.QueueFactory;
import com.jdev.util.Debug;

/**
 * <p>Title: TcpConnection</p>
 * <p>Description: </p>
 * @author Lawrence
 * @version 
 */
public class TcpConnection extends Connection {

	private final static String module = TcpConnection.class.getName();
	private final static QueueFactory queueFactory = QueueFactory.getInstance();
	private boolean isConnect = false;
	private TcpClient client = null;

	public void attach(TcpClient client) {
		this.client = client;
	}
	
	/**
	 * @param type
	 */
	public TcpConnection(int type) {
		super(type);
		try{
			if (type == ConnectionFactory.CLIENT) {
				queue = queueFactory.getQueue(QueueFactory.TCP_QUEUE);
				this.CSType = ConnectionFactory.CLIENT;
	
			} else {
				queue = queueFactory.getQueue(QueueFactory.TCP_QUEUE);
				this.CSType = ConnectionFactory.TCPSERVER;	
				isConnect = true;
	
			}
		}catch(Exception e){
			
		}
	}

	/* (non-Javadoc)
	 * @see com.jdev.net.connector.Connection#close()
	 */
	@Override
	public void close() throws Exception {
		if (!isConnect)
			return;
		try {
			client.close();
			isConnect = false;
		} catch (Exception ex) {
			Debug.logError("-->TcpConnection close error:" + ex, module);
			throw new Exception(ex);
		}
	}

	/* (non-Javadoc)
	 * @see com.jdev.net.connector.Connection#isConnect()
	 */
	@Override
	public boolean isConnect() throws Exception {
		return isConnect;
	}

	/* (non-Javadoc)
	 * @see com.jdev.net.connector.Connection#open(java.lang.String, int)
	 */
	@Override
	public void open(String url, int port) throws Exception {
		try {
			client.openSocketChannel(url, port);
			isConnect = true;
		} catch (Exception ex) {
			Debug.logError("-->TcpConnection open error:" + ex, module);
			throw new Exception(ex);
		}
	}

}

⌨️ 快捷键说明

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