作者TonyQ (骨头)
看板java
标题Re: [问题] 想用TCP写一个sever对多个client的程式
时间Sun Apr 22 21:30:11 2007
※ 引述《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