Socket programming recv () function

Source: Internet
Author: User
Tags socket error
Socket programming recv () function-general Linux technology-Linux programming and kernel information. The following is a detailed description. # Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Main ()
{Struct sockaddr_in local, server;
Int soc, soc_temp, len_server;
Int len = sizeof (struct sockaddr_in );
Char in [9999], * out = "hello word", * err;
Printf ("socket now the len is % d \ n", len );
If (soc = socket (AF_INET, SOCK_STREAM, 0) =-1)
{
Perror ("socket error! ");
Exit (0 );
}
Printf ("soc is % d \ n", soc );
Local. sin_family = AF_INET;/* 21 */
Local. sin_port = htons (3777 );
Local. sin_addr.s_addr = inet_addr ("127.0.0.1 ");
Bzero (& local, len );
If (connect (soc, (struct sockaddr *) & local, len) =-1)
{
Perror ("\ n connect error ");
Exit (0 );
}
Else printf ("\ n connectsucess \ n ");
Printf ("begian to send \ n ");
If (recv (soc, in, 999,0) =-1)
{
Perror ("errno ");
Exit (0 );
}
Else printf ("read success \ n ");
Close (soc );
Printf ("it's time to sleep ");
}
~
The following result is displayed:
Socket now the len is 16
Soc is 3

Connectsucess
Begian to send
Errno: Transport endpoint is not connected
What is the problem? Hope you can enlighten me!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.