For many Telnet protocols, such as FTP, POP3, etc., their operation is done by entering a line of characters, which requires Socket to read each time, which can be completed by the file stream (see above).
The procedure is as follows: (set SOCKFD is a connected connection descriptor)
File * cin, * cout;
Char * p, buf [1024];
CIN = FDOPEN (SOCKFD, "R");
SetBUF (CIN, (CHAR *) 0);
/ * main loop * /
While (FGETS (BUF, 1024, file)! = null) {
/ * Remove the newline character at the end of BUF * /
While ((p = & buf [strlen (buf) -1]) && (* p == '/ r' || * p == '/ n')) * p = 0;
...
}
Fclose (cin);
Close (SockFD);