"MFC Network Programming" learning Diary 1

Source: Internet
Author: User

1. Create Socket--socket ()
Function: Create a new socket before use
Format: Socket PASCAL far socket (int af,int type,int procotol);
Parameter: AF: area where communication occurs
Type: the kind of socket to be established
Procotol: The specific protocol used
2. Specify local address--bind ()
Function: Connect the socket address to the created socket size.
Format: int PASCAL far bind (SOCKET s,const struct sockaddr far Name,int
Namelen);
Parameter: s: is the socket descriptor (socket size) returned by the socket () call and not connected.
Other: No error, bind () returns 0, otherwise socket_error
Address Structure Description:
struct SOCKADDR_IN
{
Short Sin_family;//af_inet
U_short SIN_PORT;//16 bit port number, network byte order
struct in_addr sin_addr;//32 bit IP address, network byte order
Char sin_zero[8];//reserved
}
3. Establish socket connection--connect () and accept ()
Function: Work together to complete the connection
Format: int PASCAL far connect (SOCKET s,const struct sockaddr
far
Name,int
Namelen);
Socket PASCAL far accept (socket s,struct sockaddr FAR Name,int Far
Addrlen);

4. Monitor Connection--listen ()
Function: Used for a connection-oriented server, indicating that it is willing to receive connections.
Format: int PASCAL far Listen (SOCKET s, int backlog);

5. Data transmission--send () and recv ()
Function: Data sending and receiving
Format: intpascal farsend (sockets,const charfar buf,int len,int flags);
int PASCAL far recv (SOCKET s,const char
far buf,int len,int flags);
Parameter: BUF: Pointer to the buffer that contains the transmitted data.
6. Multiplexing--select ()
Function: Used to detect one or more socket states.
Format: int PASCAL far Select (Int. nfds,fd_set far readfds,fd_set
Writefds,
Fd_set far exceptfds,const struct timeval far timeout);
Parameter: Readfds: pointer to read detection
WRITEFDS: Pointer to write-detect
Exceptfds: Pointer to check for errors
Timeout: Maximum wait time
7. Close Socket--closesocket ()
Function: Close socket s
Format: BOOL PASCAL far closesocket (SOCKET s);

2.2 Socket call timing diagram with no connection protocol

MFC Network Programming learning Diary 1

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.