![]() |
从 TCP 连接中读取指定大小的数据块,结果类型为 VT_ARRAY | VT_UI1
variant = Socket.BinaryRead(nReadSize)
下面的代码创建一个 NetBox.Socket 对象,连接到 www.zydsoft.com 的 WEB 端口,发出一个请求后用 Socket.BinaryRead 读取全部返回并使用 NetBox.File 对象保存到 Socket.Log 文件中,为了演示,代码中每次只读取 20 个字节:
Set Socket = CreateObject("NetBox.Socket") Socket.Connect "zyserver1", 80 Socket.Timeout = 2000 Socket.WriteLine "GET /test.asp HTTP/1.0" Socket.WriteBlankLines 1 Set file = CreateObject("NetBox.File") file.Create "Socket.Log" Do While Not Socket.Eof file.Write Socket.BinaryRead(20) Loop Socket.Close
程序运行后,可以在 NetBox 运行目录看到一个文件 Socket.Log,其内容为:
: HTTP/1.1 404 File Not Found : Server: NetBox Version 2.01 Build 2544 : Connection: Close : Content-Type: text/html : Date: Wed, 13 Nov 2002 07:05:48 GMT : Content-Length: 101 : : <html><head><title>404 File Not Found</title></head> : <body><h1>404 File Not Found</h1></body></html>
呵呵,跟我们前面一个例子的结果完全相同。