資源簡介
實現Socket 多線程 多個客戶端同時向服務器端傳輸文件,解決并發問題和多線程。解決一個文件夾下多個文件傳輸,20秒向服務器端傳輸一個文件,直到傳輸完畢關閉連接狀態提示沒有文件。如果想發布到tomcat下 有問題的話加我QQ632167558 此程序用來學習。此程序為客戶端
代碼片段和文件信息
package?socket;
import?java.io.DataInputStream;
import?java.io.DataOutputStream;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.IOException;
import?java.io.PrintWriter;
import?java.net.Socket;
import?java.util.*;
/**
?*?本程序通過socket編程實現從客戶端發送文件到服務器端
?*?@author?×××
?*/
class?FileTimer?extends?TimerTask{
????public?void?run(){
????????byte[]?buffer?=?new?byte[1024];
????????Socket?socket?=?null?;
????????DataOutputStream??dataOut?=?null?;
????????int?length?=?0;?
????????File?f?=?new?File(“d:\\text\\“);
????????FileInputStream?fis?;
????????File[]?tempFile=f.listFiles();
????????try?{?
???????? if(tempFile.length?>0){
???????? socket?=?new?Socket(“192.168.1.170“5100);
????? ????System.out.println(“客戶端A和服務器連接成功!!“+new?Date());
????? ????data
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????586??2010-07-26?17:04??ClientSocket\.classpath
?????文件???????1045??2010-07-26?16:50??ClientSocket\.project
?????文件????????454??2010-07-26?16:50??ClientSocket\.settings\.jsdtscope
?????文件????????404??2010-07-26?17:02??ClientSocket\.settings\CVS\Entries
?????文件?????????24??2010-07-26?17:02??ClientSocket\.settings\CVS\Repository
?????文件?????????37??2010-07-26?17:02??ClientSocket\.settings\CVS\Root
?????文件????????330??2010-07-26?16:50??ClientSocket\.settings\org.eclipse.jdt.core.prefs
?????文件????????430??2010-07-26?16:50??ClientSocket\.settings\org.eclipse.wst.common.component
?????文件????????229??2010-07-26?16:50??ClientSocket\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????49??2010-07-26?16:50??ClientSocket\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2010-07-26?16:50??ClientSocket\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件????????564??2010-07-26?17:04??ClientSocket\build\classes\socket\FileClient.class
?????文件???????2307??2010-07-26?17:04??ClientSocket\build\classes\socket\FileTimer.class
?????文件????????132??2010-07-26?17:02??ClientSocket\CVS\Entries
?????文件?????????14??2010-07-26?17:01??ClientSocket\CVS\Repository
?????文件?????????37??2010-07-26?17:01??ClientSocket\CVS\Root
?????文件?????????14??2010-07-26?17:02??ClientSocket\src\CVS\Entries
?????文件?????????18??2010-07-26?17:02??ClientSocket\src\CVS\Repository
?????文件?????????37??2010-07-26?17:02??ClientSocket\src\CVS\Root
?????文件?????????49??2010-07-26?17:02??ClientSocket\src\socket\CVS\Entries
?????文件?????????25??2010-07-26?17:02??ClientSocket\src\socket\CVS\Repository
?????文件?????????37??2010-07-26?17:02??ClientSocket\src\socket\CVS\Root
?????文件???????2002??2010-07-26?16:51??ClientSocket\src\socket\FileClient.java
?????文件?????????31??2010-07-26?17:02??ClientSocket\WebContent\CVS\Entries
?????文件?????????25??2010-07-26?17:02??ClientSocket\WebContent\CVS\Repository
?????文件?????????37??2010-07-26?17:02??ClientSocket\WebContent\CVS\Root
?????文件?????????45??2010-07-26?17:02??ClientSocket\WebContent\me
?????文件?????????34??2010-07-26?17:02??ClientSocket\WebContent\me
?????文件?????????37??2010-07-26?17:02??ClientSocket\WebContent\me
?????文件?????????39??2010-07-26?16:50??ClientSocket\WebContent\me
............此處省略28個文件信息
- 上一篇:最全思科網絡設備Visio圖標庫
- 下一篇:微型計算機課程設計——溫度控制
評論
共有 條評論