用Eclipse写一个程序 ,把程序启动.例如程序的参数是新浪的IP(先在命令窗口中ping出来)和端口  然后我在浏览器中打localhost就直接跳转到新浪的网页上并把信息以Hex的形式打印在控制台上。
  (有点跟IE浏览器浏览器连接设置里面的局域网(LAN)设置大致相同)

解决方案 »

  1.   

    只要监听本机80端口就可以通过localhost访问,
    在服务端通过java.net.url取得某地址的inputstream
    把它写入socket的outputstream就可以了。你总不会是想通过socket自己组织个http协议直接发送给新浪吧。import java.io.*;
    import java.net.*;public class SocketTest
    {
    public static void main(String[] args) throws MalformedURLException, IOException
    {
    SocketTest server = new SocketTest();
    server.await();
    } public void await() throws MalformedURLException, IOException
    {
    ServerSocket serverSocket = null;
    try
    {
    serverSocket = new ServerSocket(80);
    }
    catch (IOException e)
    {
    e.printStackTrace();
    System.exit(1);
    }
    while (true)
    {
    Socket socket = null;
    InputStream input = new URL("http://www.sina.com").openStream();
    OutputStream output = null;
    try
    {
    socket = serverSocket.accept();
    output = socket.getOutputStream();
    int temp;
    while((temp=input.read())>0)
    {
    output.write(temp);
    System.out.print(Integer.toHexString(temp)+" ");
    }
    output.flush();
    output.close();
    socket.close();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    continue;
    }
    }
    }
    }