本帖最后由 215041631 于 2014-7-26 23:44 编辑
- <div class="blockcode"><blockquote>
复制代码URL url = new URL("http://192.168.1.6:10006"); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); int len =0; byte[] buf= new byte[1024]; while((len=in.read(buf))!=-1) { System.out.println(new String(buf,0,len)); } 这是客户端的代码,用的是URLConnection
- class TcpServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(10006);
- Socket s = ss.accept();
- OutputStream os = s.getOutputStream();
- os.write("wdajfhjksdhafsdjahf".getBytes());
- s.shutdownOutput();
- pw.close();
- s.close();
- ss.close();
- }
- }
复制代码- Protocol:http
- Path:
- Query:null
- Host:192.168.1.6
- Port:10006
- Exception in thread "main" java.io.IOException: Invalid Http response
- at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLCo
- nnection.java:1553)
- at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
- nection.java:1439)
- at URLDemo.main(URLDemo.java:16)
- E:\code\Net>
复制代码
这是异常提示,求大神解答下。
为什么我客户端收不到服务端发送的信息!?
如果客户端改成SOCKET连接的就没有问题,这是为啥啊
|
|