Establish a simple Web server

Source: Internet
Author: User
Tags set socket

For a client, there are two steps to establishing a TCP connection, including establishing a socket object and calling connect () to establish a connection to the server.

Four steps required for the server:

  1. To create a socket object:

s = socket.socket (socket.af_inet, socket. SOCK_STREAM)

2. Set socket options (optional)

S.setsockopt (socket. Sol_socket, SOCKET. SO_REUSEADDR, 1) #把socket设置成可复用的

3. Bind a port, you can also make a network card!

S.bind ((host, Port))

4. Listening for connections

S.listen (5) #调用listen函数, waiting for the client to connect, with a maximum of one pending connection per time


This article is from "Custom" blog, declined reprint!

Establish a simple Web 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.