JavaSocketsisaclasslibraryimplementingasubsetoftheC++Socketslibrary,andisbasedonSUN'sjava.nio.*non-blockingnetworki/oclasses.
示例代码
publicclassMySocketextendsTcpSocket{publicMySocket(SocketHandlerh){super(h);SetLineProtocol();}publicvoidOnConnect(){Send("GET/HTTP/1.0\r\n"+"Host:www.alhem.net\r\n"+"\r\n");}publicvoidOnLine(Stringline){System.out.println(line);}publicstaticvoidmain(String[]args){StdLoglog=newStdoutLog();SocketHandlerh=newSocketHandler(log);MySocketsock=newMySocket(h);sock.Open("www.alhem.net",80);h.Add(sock);booleanquit=false;while(!quit)//forever{h.Select(1,0);}}}
评论