Chapter 4 network server

Source: Internet
Author: User

To create a TCP server: Create a socket object, set the socket option, bind it to a port, and listen for the connection.

1. Establish a connection.

S = socket. socket (socket. af_inet, socket. sock_stream)

Ii. Set options (optional)

S. setsockopt (socket. sol_socket, socket. so_reuseaddr, 1)

For specific options, see socket (7) manual.

3. Bind a port

S. BIND ('', 80)

Iv. Listener connection

S. Listen (5)

The server must consider the exception handling situation and ensure that the service does not stop due to exceptions.


Create the pseudocode Of The UDP Server:

Ss = socket () ss. BIND () inf_loop: Ss. recvfrom ()/SS. sendto () ss. Close ()


This article from the "Lotus miss" blog, please be sure to keep this source http://liandesinian.blog.51cto.com/7737219/1551380

Chapter 4 network server

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.