A Simply Client Code for That Server.

xiaoxiao2021-03-06  74

#include

#include #include #include #include

#define port 3490 # Define MaxDataSize 1000INT Main (int Argc, char * argv []) {charf [maxdatasize]; int sockfd; int numBytes; struct sockaddr_in thereir_addr;

IF (argc! = 2) {Printf ("USAGE: Client Hostip / N"); exit (1);}

IF ((Sockfd = Socket (AF_INET, SOCK_STREAM, 0) == - 1) {Printf ("socket"); exit (1);

THEIR_ADDR.SIN_FAMILY = AF_INET; THEIR_ADDR.SIN_PORT = HTONS (port); their_addr.sin_addr.s_addr = inet_addr (Argv [1]); MEMSET (& (THEIR_ADDR.SIN_ZERO), '/ 0', 8);

IF (Connect (STRUCKD, STRUCKADDR *) & THEIR_ADDR, SIZEOF (STRUCKADDR)) == - 1) {Printf ("Connect"); Printf ("" The port of this host is: / t open "); EXIT 1); }

IF ((NumBytes = Recv (SockFD, BUF, MaxDataSize-1, 0)) == - 1) {Printf ("RECV");}

BUF [NumBytes] = '/ 0';

Printf ("ReceiveD:% S", BUF); Close (SockFD); Return 0;}

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

New Post(0)