作者TonyQ (骨头)
看板java
标题Re: [问题] socket 传输输入字串的问题
时间Sun Apr 9 13:45:20 2006
※ 引述《[email protected] (飞)》之铭言:
: while ((str=br.readLine()) != null)
: {
: //your processing
: }
请问这位兄台 ^^ 您的这段程式码要放在哪才能正常执行呢?
看来看去,真的看不懂这个问题跟兄台您所给的程式码的关连性。
故想请教之,看来小弟对於Socket还没悟通。^^"
因为照程式码
这些readLine()应该都没有null当EOF ^^"
只是一直互相的waiting对方的input罢了
根据小弟愚见
这个程式会变成dead lock
是因为server端的readLine()
输入的时候并不会把'\n'写入
所以Server在没有读到'\n'当EOF的状态下
(因为是透过readLine() 所以是抓'\n')
也就是 server端的
String instring = in.readLine();
这行一直处於等待'\n'的状况
而client端也在等待server端的输出
两边互等的结果就没完没了了XD
小弟比较笨,只会用比较笨的解法,
只要在Client端的readLine() 後加上 '\n' 当EOF 就可以解决了。^^"
也就是改成这样
String str=br.readLine()+'\n';
To chairs:
稍微说明一下程式目的,会让人比较容易回答问题,
也比较不会误解问题。
另外,其实你的测试用String都已经告诉你答案了。:P
GL & HF
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the complier will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.pratice()); | Bone
everything
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.138.240.57