//TCP客户端
import java.net.*;
import java.io.*;
class TCPclient
{
public static void main(String[] args)
{
try
{
Socket s = new Socket("192.168.1.101",10005);
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufOut = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = null;
while ((line=bufr.readLine())!=null)
{
if ("over".equals(line))
break;
bufOut.write(line);
bufOut.newLine();
bufOut.flush();
String str = bufIn.readLine();
System.out.println(str);
}
bufr.close();
s.close();
}
catch (Exception e)
{
System.out.println("over");
}
}
}
为什么运行结果是 over ?
而不是等待键盘录入的呢 , 找了很久,就是没找到问题所在。 |