用Eclipse写一个程序 ,把程序启动.例如程序的参数是新浪的IP(先在命令窗口中ping出来)和端口 然后我在浏览器中打localhost就直接跳转到新浪的网页上并把信息以Hex的形式打印在控制台上。
(有点跟IE浏览器浏览器连接设置里面的局域网(LAN)设置大致相同)
(有点跟IE浏览器浏览器连接设置里面的局域网(LAN)设置大致相同)
解决方案 »
- 怎么从一个文本中把内容读出来并写到另一个文本中
- 关于java程序打jar包问题
- 使用Struts时,遇到的问题:does not contain handler parameter named method . this may be caused by whitespace in the label text.异
- 关于Jsoup正则表达式
- 一口气问几个java入门级问题,菜鸟和高手都请进!
- 高分征求各种棋类游戏算法或程序
- 菜鸟遇到流错误
- java中没有专门复制文件的copy函数吗?难道这种底层函数要自己写?
- 960分,求mdb数据库格式的英汉,汉英字典,四六级,gre,toefl
- NetBeans6.1开发j2me 需要什么插件?谢谢啊
- 写入数字和读取数字问题
- 求大能帮助:以下不属于AWT库中定义的类是???
在服务端通过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;
}
}
}
}