Use Sockets in PHP: Get your article from newsgroups

xiaoxiao2021-03-06  63

Use Sockets in PHP: Get your article from newsgroups

Author: Forever Unix Joined: 2004-07-09 Views: 61 PHP Socket can open ports on a remote or local host. This article is a small example of Socket: Connect to a USENET newsgroup server, dialogue with the server, download some articles from the news group. Open a socket in PHP to open a socket using fsockopen (). This function can be used in PHP3 and PHP4. The function declaration is like this: int fsockopen (String Hostname, int port [, int errno [, string errstr [, double timeout]]) This function opens a TCP connection to the port port connected to the host Hostname. Hostname can be a valid domain name or an IP address. For UDP connections, you must specify protocols: udp: // hostname. For UNIX domain, host names use the path to the socket, in which case port port must be 0. Optional Timeout parameters are used to set the time waiting to open a socket, in seconds. For more information about fsockopen (), please refer to: h ttp: //www.php.net/manual/function.fsockopen.php Network News Transfer Protocol Access News Group Server needs to be called NNTP (Network News Transfer Protocol) The agreement is carried out. This protocol has detailed details in RFC977, which can be obtained at http://www.w3.org/protocols/rfc977/rfc977.html. This document describes how to connect to an NNTP server, how to talk to server dialogue, and different commands that complete these tasks. Connection to a NNTP server needs to know its hostname (or IP address) and the port it listens. To avoid a connection attempt failure, you should use the TIMEOUT parameter. Dialogue with the server now we have connected to the server, you can talk to the server with the server through the Socket you open. For example, we have to get a recent 10 articles from a news group. RFC977 pointed out that the first step is to select the correct newsgroup with the group command: Group GGG parameter GGG is the name of the newsgroup to be selected (for example, "net.news"), it is necessary. A list of available new smelling groups can be obtained with a list command. After selecting the command of the newsgroup, return to the article number of the first and the last article in the group, and the number of articles in the group.

转载请注明原文地址:https://www.9cbs.com/read-111004.html

New Post(0)