2017-10-17 9 views
-1

私は、クライアントからサーバーにファイルを送信するときに、複数のポートとマルチスレッドサーバーを使用します。しかし、私は異なるポートに同時にデータを送信することはできません。私はパラレルプログラミングを使用しなければならないと思います。ソリューションの提案はありますか?このトピックのソースまたはインターネットウェブサイトの提案を教えてください。マルチスレッドサーバー複数ポート送信ファイル同じ時刻

サーバー側

SendFiletoClient(DataSocket1, "test1.txt"); 
SendFiletoClient(DataSocket2, "test2.txt"); 
SendFiletoClient(DataSocket3, "test3.txt"); 
SendFiletoClient(DataSocket4, "test4.txt"); 

マルチスレッドサーバー用のパターンが何か擬似として符号化される

addFileToClient(Socket1, "test1.txt"); 
addFileToClient(Socket2, "test2.txt"); 
addFileToClient(Socket3, "test3.txt"); 
addFileToClient(Socket4, "test4.txt"); 
+0

「私は皿洗い可能な港を使わなければならないのは分かりますか?」 "serilazable port"とは何ですか? – Kayaman

答えて

1

クライアント側:

//server side 
while (true) { 
    accept a connection; 
    create a thread to deal with the client; 
} 

以上の建設的な方法で:

while(this.isRunning) { 
    Socket clientSocket = null; 
    try { 
     clientSocket = this.serverSocket.accept(); 
    } catch (IOException e) { 
     //handle exception on accept client socket 
    } 
    if(clientSocket != null) { 
     Thread workerThread = new Thread(
      new YourWorkerRunnable(clientSocket /*, remain arguments */)); 
     workerThread.start(); 
    } 
} 

このパターンのバリエーションには、サーバー側のリソース割り当て管理を改善するためのworkerThreadsのプールが含まれています。

サーバソケットのコーディングの詳細については、to this linkを参照してください。

関連する問題