Java SocketsJava Socket类库

联合创作 · 2023-09-29 10:49

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.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);
}
}
}
浏览 10
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报