gsipserver.java

来自「是一款国外的网络游戏平台的源码*不是类似浩方那种虚拟局域网技术」· Java 代码 · 共 63 行

JAVA
63
字号
/*
 * Created on Jan 8, 2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.GTADS.server;

import java.io.IOException;
import java.net.*;

import org.GTADS.debug.ServerLogger;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GSIPServer extends Thread {
	public static GSIPServer instance;
	private ServerSocket GSIPSocket;
	private Socket clientConnection;
	
	public static GSIPServer getInstance(){
		if (instance == null){
			instance = new GSIPServer();
		}
		return instance;
	}
	
	public static void clearInstance(){
		if (instance != null){
			instance = null;
		}
	}
	
	public GSIPServer() {
		start();
	}
	
	private void listenForClients() throws IOException{
		GSIPSocket = new ServerSocket(ServerConfig.getInstance().getGSIPPort());
		ServerLogger.sendConsoleOutput("GSIP Server started on port " + ServerConfig.getInstance().getGSIPPort(),
				this.getClass());
		while(true) {
			clientConnection = GSIPSocket.accept();
			ServerLogger.sendConsoleDebugMessage("Incoming Connection on GSIP Server", this.getClass(), 5);
			new GSIPSThread(clientConnection);
		}
	}
	
	public void run() {
		try {
			listenForClients();
		} catch (IOException ioe){
			ServerLogger.sendConsoleOutput("GSIP Server not started", this.getClass());
			ServerLogger.sendConsoleDebugMessage("GSIP Server Port " + ServerConfig.getInstance().getGSIPPort() +
					" used by another process!", this.getClass(), 2);
		}
	}
}

⌨️ 快捷键说明

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