我通过浏览器可以访问,服务端可以收到客户端的请求,我在命令行输入telnet 命令后客户端一直阻塞,但是服务端显示连接了,ctrl+c 停止客户端后,服务端收到客户端的请求是一个字符,客户端这时收到了服务端发送的数据。求解释?
这是服务端的截图:
代码:- import java.net.*;
- import java.io.*;
- class ServerDemo
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(5000);
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println("ip::"+ip);
- InputStream is = s.getInputStream();
- byte[] buff = new byte[1024];
- int len = is.read(buff);
- System.out.println(new String(buff,0,len));
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- out.println("<font color='red'size='7'>客户端你好!!!</font>");
- s.close();
- ss.close();
- }
- }
复制代码 |
|