Read a line of statements from Socket

xiaoxiao2021-03-06  80

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);

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

New Post(0)