我們的項目是用DotNet實現Socket連接
private Socket clientSocket;
public void Start()
{
Thread thread=new Thread(new ThreadStart(MainService));
thread
}
void MainService()
{
listener=new TcpListener(
listener
while(true)
{
Socket s= listener
clientSocket=s;
Thread clientservice = new Thread(new ThreadStart(ClientService));
clientservice
Thread
}
}
void ClientService()
{
string command;
string receiveStr;
string fileName
Socket sock=clientSocket;
EndPoint oldEP=sock
byte[] bb=new byte[
while(true)
{
ii=sock
if(ii==
{
break;
}
receiveStr=Encoding
command=ReadLineFrom(receiveStr
Switch(command)
{
cace
fileName=ReadLineFrom(receiveStr
fileSize=ReadLineFrom(receiveStr
uploadFile(sock
break;
}
}
void uploadFile(Socket sock
{
int loadSize=
byte[] bb;
int blen=
NetworkStream stream=new NetworkStream(sock);
FileStream fs=File
while(loadSize {
if(loadSize>fileSize
blen=fileSize
bb=new byte[blen];
int ii=stream
fs
loadSize+=ii;
}
fs
stream
}
判斷客戶端是否斷開要用這個方法實現
客戶端我就不寫了
這些問題解決了
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26331.html