本帖最后由 寇弘禄 于 2013-4-3 08:52 编辑
我的电脑无法访问127.0.0.1 和localhost,重装之前能访问着,现在不能访问了,什么原因,系统是盗版的。- package test;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.net.UnknownHostException;
- class Test{
- public static void main(String[] args) throws IOException{
- Socket s = new Socket("127.0.0.1",10003);
- OutputStream out = s.getOutputStream();
- out.write("你好".getBytes());
- out.flush();
- s.close();
- }
- }
- class B{
- public static void main(String[] args) throws IOException{
- ServerSocket ss = new ServerSocket(10003);
- Socket s = ss.accept();
- InputStream in = s.getInputStream();
- byte[] b = new byte[1024];
- int len = 0;
- len = in.read(b);
- System.out.println(new String(b,0,len));
- s.close();
- ss.close();
- }
- }
复制代码 |