dataoutput.close();
fs.close();
dataSocket.close();
cmdinput.readLine();//服务器文件读入结束
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
}
break;
4 服务器端实现
4.1 receive.XML
cmdport为命令接收端口,datport为数据接收端口,根据客户端上传的localemachineident和localeupident找到第一个元素directoryreceive,读其中的参数:
<root>
<serverip>11.68.17.167</serverip>
<cmdport>10013</cmdport>
<datport>10014</datport>
<!-- 接收目录 -->
<directoryreceive>
<!-- 客户机在服务器配置中的源主机编号 -->
<localemachineident>1</localemachineident>
<!-- 客户机在服务器中的源目录编号,源主机编号加源目录编号唯一确定一个上传线程 -->
<localeupident>1</localeupident>
<!-- 接收策略 -->
<receivetrategy trategy="weekcycle"/>
<!-- 路径名不能为"\",必须为"/"或"\\(windows)" -->
<receiverootdirectory>f:/test1</receiverootdirectory>
</directoryreceive>
4.2 TransfileServer.Java
服务器端ServerSocket监听,当与客户端建立一个Socket连接时,创建处理线程:
ReceiveFileDir receivefiledir=new ReceiveFileDir(cmdSocket,document,datss);
receivefiledir.start();
4.3 ReceiveFileDir
读入客户机上传的localemachineident和localeupident,根据上传目录或文件及接收目录封装方式(WeekCycle)分别调用ReceiveDir.Java、ReceiveFile.Java。
4.4 ReceiveDir和ReceiveFile
接收客户端上传的数据,并保存到服务器指定目录:
else if(cmdpara.equals("file"))
{
File file=new File(root+"/"+param);
file.delete();
System.out.println(root+"/"+param);
RandomAccessFile fout;
try {
|