当前位置: 软件>java软件
Java Socket类库 Java Sockets
来源: http://www.oschina.net/p/java+sockets
发布时间:2015-02-05
本文导语: Java Sockets is a class library implementing a subset of the C++ Sockets library, and is based on SUN's java.nio.* non-blocking network i/o classes. 示例代码 public class MySocket extends TcpSocket{ public MySocket(SocketHandler h) { super(h); SetLineProtocol(); } public void OnConnect() {...
Java Sockets is a class library implementing a subset of the C++ Sockets library, and is based on SUN's java.nio.* non-blocking network i/o classes.
示例代码
public class MySocket extends TcpSocket
{
public MySocket(SocketHandler h)
{
super(h);
SetLineProtocol();
}
public void OnConnect()
{
Send("GET / HTTP/1.0rn" +
"Host: www.alhem.netrn" +
"rn");
}
public void OnLine(String line)
{
System.out.println(line);
}
public static void main(String[] args)
{
StdLog log = new StdoutLog();
SocketHandler h = new SocketHandler(log);
MySocket sock = new MySocket(h);
sock.Open( "www.alhem.net", 80 );
h.Add( sock );
boolean quit = false;
while (!quit) // forever
{
h.Select(1, 0);
}
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。