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

📄 socketchannel.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 * Created on 08-May-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.maverick.multiplex;

import java.io.IOException;
import com.maverick.crypto.io.*;
import java.net.*;

/**
 * @author lee
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SocketChannel extends Channel {

	String hostname;
	int port;
	Socket socket;
	IOStreamConnector input;
	IOStreamConnector output;

	public SocketChannel(Socket socket, String hostname, int port) {
		super("socket-channel", 34000, 32768);
		this.socket = socket;
		this.hostname = hostname;
		this.port = port;
	}

	public SocketChannel() {
		super("socket-channel", 34000, 32768);
                this.equals(null);
	}


	/* (non-Javadoc)
	 * @see com.maverick.multiplex.MultiplexChannel#open(int, byte[])
	 */
	public byte[] open(byte[] data) throws IOException {
		ByteArrayReader reader = new ByteArrayReader(data);
		hostname = reader.readString();
		port = (int)reader.readInt();

		socket = new Socket(hostname, port);

		return null;
	}

	/* (non-Javadoc)
	 * @see com.maverick.multiplex.MultiplexChannel#create()
	 */
	public byte[] create() throws IOException {

		ByteArrayWriter msg = new ByteArrayWriter();
		msg.writeString(hostname);
		msg.writeInt(port);
		return msg.toByteArray();
	}

	public void onChannelOpen() {

		try {
		input = new IOStreamConnector(socket.getInputStream(),
				getOutputStream());
		output = new IOStreamConnector(getInputStream(),
				socket.getOutputStream());
		} catch(IOException ex) {
			close();
		}
	}

	public void onChannelClose() {
		if(input!=null)
			input.close();
		if(output!=null)
			output.close();
	}

}

⌨️ 快捷键说明

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