Java Socket类库 Java Sockets
fmms
13年前
<p>Java Sockets是C++ Sockets的一个子集Java实现类库。基于<span>java.nio.*</span> non-blocking network i/o 类实现。<br /> </p> <p>示例代码:</p> <pre class="brush:java; toolbar: true; auto-links: false;">public class MySocket extends TcpSocket { public MySocket(SocketHandler h) { super(h); SetLineProtocol(); } public void OnConnect() { Send("GET / HTTP/1.0\r\n" + "Host: www.alhem.net\r\n" + "\r\n"); } 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); } } }</pre> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1325819616546" target="_blank">http://www.open-open.com/lib/view/home/1325819616546</a></p> <p></p>