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

📄 multithreadedremotefileserver.java

📁 java socket基础编程实例
💻 JAVA
字号:
   /*
	* Name of the Application     : MultithreadedRemoteFileServer.java
	* Development Environment     : Eclipse3.0M8
	* @Version 1.0
	* Describtion 
	* 
	*	1)response requests from the client for the file  
	*
	*
	* Creation / Modification History
	*	wsl	19:30 06/29/2004	Creation       
	*
	* Copyright ® 2004 www.cnlab.net
	* All right reserved. 
	*/
package net.cnlab.wsl.testsocket.multithread;

import java.io.*;
import java.net.*;
public class MultithreadedRemoteFileServer {
	
	protected int listenPort;
	
	public MultithreadedRemoteFileServer(int aListenPort) {
		listenPort = aListenPort;
	}
	public void acceptConnections() {
		try {
			ServerSocket server = new ServerSocket(listenPort, 5);
			Socket incomingConnection = null;
			System.out.println("the MultiThreadServer is running...");
			while (true) {
				incomingConnection = server.accept();
				handleConnection(incomingConnection);
			}
		} catch (BindException e) {
			System.out.println("Unable to bind to port " + listenPort);
		} catch (IOException e) {
			System.out.println("Unable to instantiate a ServerSocket on port: " + listenPort);
		}
		}
		public void handleConnection(Socket connectionToHandle) {
			new Thread(new ConnectionHandler(connectionToHandle)).start();
		}
		public static void main(String[] args) {
			MultithreadedRemoteFileServer server = new MultithreadedRemoteFileServer(3001);
			server.acceptConnections();
		}
}

⌨️ 快捷键说明

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