Re: [問題] 想用TCP寫一個sever對多個client的程式
※ 引述《newpuli (sheepu)》之銘言:
: 想要一個sever 對多個client
: 並配合TCP協定
: 以下是sever的建立連線方式
: private ServerSocket server;
: private Socket connection;
: server = new ServerSocket(12345);
: connection = server.accept();
: 要怎麼樣做才會有這種一對多的效果呢?
簡單來說一次accept只會接到一個clinet,
如果你想接到多個client 就要accept多次。
但是server to client 是單thread,所以你的server 或許需要 ,
每來一個clinet就專門開一個thread去處理clinet過來的資訊,
就這樣。 \@_@/
如果你的資料處理不是同時的話,可以考慮用排隊的方式,
等A處理完再開放B進來處理,這樣就不用做multi-thread。
一切要看你的 case 需求是甚麼。
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.27.68
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 5 篇):