java的多线程ftp服务器

此程序是应用java中的网络套接字实现的对服务器的链接,利用多线程来实现多个客户端的接入

package com.ltb.server;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class ReceiveServer {
private final  int RECEIVE_PORT=9090;
public ReceiveServer(){
ServerSocket ss;
try {
ss = new ServerSocket(RECEIVE_PORT);
System.out.println("welcome to the Server"+new Date()+"the Server is read");
while(true){
Socket s=ss.accept();
Thread serverthread=new ServerThread(s);
serverthread.start();
}
} catch (IOException e) {
e.printStackTrace();
}


}
public static void main(String[] args) {
new ReceiveServer();
}

}

此类属于内部类

class ServerThread extends Thread{
Socket s;
BufferedReader input;
PrintWriter output;
public ServerThread(Socket s) {
this.s = s;
InputStreamReader read;
OutputStreamWriter writer;
try {
read=new InputStreamReader(s.getInputStream());
writer=new OutputStreamWriter(s.getOutputStream());
input=new BufferedReader(read);
output=new PrintWriter(writer);
} catch (IOException e) {
e.printStackTrace();
}
output.println("welcom to the server");
output.println("time"+new Date()+"Port"+s.getLocalPort());
output.println("whate cann I do for you ?");
}
public void run() {
String cmd=null;
boolean  boon=false;
while(!boon){
try {
cmd=input.readLine();
if(cmd!=null&&cmd.equalsIgnoreCase("quit")){
boon=true;
}else if(cmd.startsWith("HELP")){
output.println("");
output.println("quer");
output.println("pwd");
output.println("cd");
}
} catch (IOException e) {
e.printStackTrace();
}

}


}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值