当服务器端的监听在 循环里面的时候 发现 不正正常接收客户端的信息
把监听accept放在循环外面却可以,刚学到这里,不是很理解!
大神路过帮忙解答下,谢谢!
public class TcpClient {
public static void main(String[] args) {
//创建套接字
Socket s = null;
//创建键入字符流
BufferedReader reader = null;
//创建输出字符流
BufferedWriter writer = null;
try {
//实例化套接字
s = new Socket("127.0.0.1",10011);
System.out.println("TCP 已启动 请输出您要发送的信息......");
//获得此套接字输出流
OutputStream out = s.getOutputStream();
//实例化输入流
reader = new BufferedReader(new InputStreamReader(System.in));
//实例化输出流
writer = new BufferedWriter(new OutputStreamWriter(out));
//保存读入信息
String line = null;
while (true){
line = reader.readLine();
writer.write(line);