My code of my TCP server segment

xiaoxiao2021-04-02  205

#include #include #include int main () {

Int socketfd, consocketfd, n; char send_str [1024]; struct sockaddr_in serddr;

IF ((socketfd = socket (AF_INET, SOCK_STREAM, 0) <0) {Printf ("CREATE SOCKET ERROR!");

Bzero (& Seraddr); seraddr.sin_family = af_inet; serddr.sin_addr.s_addr = htonl (inaddr_any); serddr.sin_port = htons (13);

IF (Bind (STRUCKETFD, STRUCKADDR *) & seraDDR, SIZEOF (SERADDR)) <0) {Printf ("Bind Socket Error!");} IF (Listen (Socketfd, 1024) <0) {Printf ("Listen Socket Error! ");

For (;;) {IF ((Consocketfd = Accept (Socketfd, (Struct SockAddr *) NULL, NULL) <0) {Printf ("Listen Socket Error!");} Sprintf (send_str, "% s / n" , "IT IS Xuang Sending ..."; if (Write (consocketfd, send_str, strlen (send_str))! = Strlen (send_str)) {Printf ("Write Socket Error!");}

IF (close (consocketfd) == - 1) Printf ("Close Socket Error!");}}

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

New Post(0)