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

📄 connection.java

📁 JAVA平台下优秀的CHART开源代码,可以实现类似EXCEL中的二维或三维的饼图/椎图功能.
💻 JAVA
字号:
/**
 * Copyright (C) 2003  Manfred Andres
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/**
 * The Connection-class is used to store connection-specific data
 * only once. 
 */
package freecs.content;

import freecs.Server;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.nio.channels.SelectionKey;

public class Connection {
	// this is the remote-address of the socket-connection
	public InetAddress		remoteAddress = null;
	public String 			remoteIp = null;
	
	// this represents the real-client-ip if it has been identified
	public String 			realIp=null;
	public InetAddress		realAddress=null;
	
	// this is the proxy forward-chain (from the xForwardedFor headerfield)
	public String[]			fwChain = null;
	
	// true if the client has a direct-socket-connectino
	public boolean			isDirectlyConnected=true;
	
	public Connection (SelectionKey sk) {
		remoteAddress 	= ((SocketChannel) sk.channel()).socket().getInetAddress();
		remoteIp 		= remoteAddress.getHostAddress();
		realAddress 	= remoteAddress;
		realIp 			= remoteAddress.getHostAddress();
	}
	
	public Connection (SelectionKey sk, String[] fwChain, boolean idc) {
		isDirectlyConnected 	= idc;
		remoteAddress 			= ((SocketChannel) sk.channel()).socket().getInetAddress();
		if (remoteAddress != null)
			remoteIp			= remoteAddress.getHostAddress();
		if (fwChain != null) {
			isDirectlyConnected 	= false;
			this.fwChain 			= fwChain;
			if (fwChain[0].indexOf(".") > -1) try {
				realAddress = InetAddress.getByName(fwChain[0]);
				if (realAddress != null)
					realIp 		= realAddress.getHostAddress();
			} catch (UnknownHostException uhe) {
				Server.debug ("Unable to determine real IP for " + fwChain[0], uhe, Server.MSG_STATE, Server.LVL_MINOR);
			}
			return;
		} else if (!idc) {
			return;
		}
		realAddress = remoteAddress;
		if (remoteAddress != null)
			realIp 		= realAddress.getHostAddress();
	}

	private String toStringVal = null;	
	public String toString () {
		if (toStringVal == null) {
			StringBuffer sb = new StringBuffer ();
			if (!isDirectlyConnected)
				sb.append ("proxy=");
			sb.append (remoteIp);
			if (!isDirectlyConnected && realIp != null) {
				sb.append (" realIp=");
				sb.append (realIp);
			}
			toStringVal=sb.toString();
		}
		return toStringVal;
	}
}

⌨️ 快捷键说明

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