# Include <stdio. h>
# Include <sys/socket. h>
# Include <netinet/in. h>
Static char out_ip [15] = "52.0.10.188 ";
Static int out_port = 8888;
Int main ()
{
Char ssendbuf [2049], srecvbuf [2049];
Int connfd = 0, iret = 0, isendlen = 0;
Struct sockaddr_in servaddr;
File * FP;
Char sfilename [128];
Memset (ssendbuf, 0, sizeof (ssendbuf ));
Memset (srecvbuf, 0, sizeof (srecvbuf ));
Memset (sfilename, 0, sizeof (sfilename ));
Bzero (& servaddr, sizeof (servaddr ));
Servaddr. sin_family = af_inet;
Servaddr. sin_port = htons (out_port );
Inet_ton (af_inet, out_ip, & servaddr. sin_addr );
Sprintf (sfilename, "/home/AP/dcclink/. Shan/practice/test. log ");
Fp = fopen (sfilename, "W + ");
If (FP = NULL)
{
Printf ("fopen Err! \ N ");
Return-1;
}
Connfd = socket (af_inet, sock_stream, 0 );
If (connfd <0)
{
Printf ("socket Err! ");
Close (FP );
Return-1;
}
Iret = connect (connfd, (struct sockaddr_in *) & servaddr, sizeof (servaddr ));
If (iret <0)
{
Printf ("Connect Err! ");
Close (FP );
Close (connfd );
Return-2;
}
Sprintf (ssendbuf, "% 01028 s", "aaaaaaaaaa ");
Isendlen = strlen (ssendbuf );
Fprintf (FP, "ssendbuf [% s], isendlen [% d]", ssendbuf, isendlen );
Isendlen = Send (connfd, ssendbuf, isendlen, 0 );
If (isendlen <= 0)
{
Printf ("Send Err! \ N ");
Close (FP );
Close (connfd );
Return-3;
}
Close (FP );
Close (connfd );
Return 0;
}