首先你是通过代理上网还是通过拨号?
如果拨号的话应该可以的。
如果代理的话估计用socket不行,你可以用java.net.URL类和java.net.URLConnection类来访问,当然要在系统属性中指定代理服务器和端口.
something like: URL url1=new URL("www.sina.com.cn:80");
System.getProperties().setProperty("proxySet","true");
System.getProperties().setProperty("proxyHost","代理服务器"); System.getProperties().setProperty("proxyPort","80");
URLConnection urlcon=url1.openConnection();
DataInputStream dis=new DataInputStream(urlcon.getInputStream());
while((msg=dis.readLine())!=null){
System.out.println(msg);
}
论坛上有关于这方面的资料可以查找。
如果拨号的话应该可以的。
如果代理的话估计用socket不行,你可以用java.net.URL类和java.net.URLConnection类来访问,当然要在系统属性中指定代理服务器和端口.
something like: URL url1=new URL("www.sina.com.cn:80");
System.getProperties().setProperty("proxySet","true");
System.getProperties().setProperty("proxyHost","代理服务器"); System.getProperties().setProperty("proxyPort","80");
URLConnection urlcon=url1.openConnection();
DataInputStream dis=new DataInputStream(urlcon.getInputStream());
while((msg=dis.readLine())!=null){
System.out.println(msg);
}
论坛上有关于这方面的资料可以查找。
可我是通过拨号上去的呀!
结果是死循环
while (true) {
numBytes = inStream.read(readBuffer); //read(byte[]):当读到末尾时返回-1
if ( numBytes == -1 ){ //改一下判断条件
System.out.println("I'm successful!");
break;
}
System.out.println("had received something!")
}
import java.net.*;public class JabberServer {
// Choose a port outside of the range 1-1024:
public static final int PORT = 8080;
public static void main(String[] args)
throws IOException {
ServerSocket s = new ServerSocket(PORT);
System.out.println("Started: " + s);
try {
// Blocks until a connection occurs:
Socket socket = s.accept();
try {
System.out.println(
"Connection accepted: "+ socket);
BufferedReader in =
new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
// Output is automatically flushed
// by PrintWriter:
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())),true);
while (true) {
String str = in.readLine();
if (str.equals("END")) break;
System.out.println("Echoing: " + str);
out.println(str);
}
// Always close the two sockets...
} finally {
System.out.println("closing...");
socket.close();
}
} finally {
s.close();
}
}
} ///:~
to backlove(bingo):为什么贴个server端的程序上来,是何作用?
其实我就是想知道我的inStream没有读到任何信息的原因。
另外与其用循环读取inStream.read(readBuffer);方法不如直接用一个读取阻塞的方法,如:上面blacklove的BufferReader类的readLine()方法。
另外问一句,你怎么知道所连的服务器6000端口是监听的,并能返回信息给你的?
有人用吗?上面似乎有一位兄弟在用:)
我在试着按照Gnutella协议连接Gnutella主机,主机是该协议发布网站提供的,所以应该是没问题的啦!to dx(东邪):
我有空的时候也看TIJ的。 to yangzi(笨笨):
我没有用到Applet。
我在用,hehe,那段代码就是那书上的