TCP Network Programming process

Source: Internet
Author: User

TCP Network Programming process


Sockets

STRUCTSOCKADDR{//Universal Socket Data structure

sa_family_tsa_family;//Protocol Family

charsa_data[14];//Protocol Family Data

}


Actual use of sockaddr_in, forced conversion at bind or connect

structsockaddr_in{//Ethernet Socket Data structure

U8sin_len;

u8sin_familly;

U16sin_port;

STRUCTIN_ADDRSIN_ADDR;

CHARSIN_ZERO[8];

}


Server-side: Socket ()->bind ()->listen ()->accept ()->read ()->write ()->close ()

Client: Socket ()->connect ()->write ()->read ()->close ()



Socket () Create socket, return file descriptor

Prototype: intsocket (int domain,int type,int protocol);

Domain setting communication, specifying the protocol family

Pf_unix,pf_local

Local communication

Pf_inet

Ipv4internet protocol

Pf_inet6

Ipv6internet protocol

Pf_ipx


Pf_netlink

Kernel user Interface Devices

pf_x25


pf_ax25


Pf_atmpvc


Pf_appletalk


Pf_packet

Underlying package access

The value and meaning of type

Sock_stream

TCP connections

Sock_dgram

Udp

Sock_seqpacket

Serialization Package

Sock_raw

Provides access to the original network protocol

Sock_rdm

Provides a reliable type of data message, but may have a disorderly sequence of data

Sock_packet

Dedicated type, receiving data from device drivers


protocol specifies the specific type of a protocol,



Bind () binds an address port

Prototype: intbind (int sockfd,const struct sockaddr *my_addr,socklen_t addrlen);


Listen () Listening on the local port

Prototype: intlisten (int sockfd,int backlog);

The backlog represents the length of the client waiting in the queue before the accept process.



Accept ()

Prototype: intaccept (int sockfd,struct sockaddr *addr,socklen_t *addrlen);

Addr is a pointer that returns a pointer to the address of the client.


Connect ()

Prototype: intconnect (int sockfd,struct sockaddr *,int addrlen);

Write ()

Read ()


Close ()


Shutdown ()

Prototype: intshutdown (int s,int how)

Allow more ways to close sockets

Shut_rd

Cut Read

Shut_wr

Cut Write

Shut_rdwr

Cut read and write, same as close ()



Signal:

When trying to write, if the server is closed, get a sigpipe signal and terminate the process


This article is from the "No Front" blog, please be sure to keep this source http://qianyang.blog.51cto.com/7130735/1615335

TCP Network Programming process

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.