[PYTHON] Overview of how to create a server socket and how to establish a client socket

After making the server socket Roughly how to make a socket corresponding to the connected client socket.

How to make a server socket

Create a TCP socket and fix it with host and ip

example


s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s_socket.bind((socket.gethostname(), 80))
serversocket.listen(5)

Make a client socket with the connected socket

It does not send or receive data. Corresponding to the connected client socket, Create a client socket to handle on the server side.

example


while True:
    (clientsocket, address) = serversocket.accept()
    ct = client_thread(clientsocket)
    ct.run()

Create a client socket for the connected socket. Keep doing this earnestly. The socket created above speaks on its own and automatically allocates ports.

Also, the client socket on the user side and the client socket on the server side are the same type.

The above, how to handle the client socket in the server and how to handle send or recv are separate.

Recommended Posts

Overview of how to create a server socket and how to establish a client socket
How to create a simple TCP server / client script
Overview of Python virtual environment and how to create it
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
How to create a Conda package
How to create a virtual bridge
How to create a Dockerfile (basic)
Create a Unix Domain Socket server
How to create a config file
How to start a simple WEB server that can execute cgi of php and python
[C language] How to create, avoid, and make a zombie process
How to create a large amount of test data in MySQL? ??
How to create a clone from Github
How to split and save a DataFrame
How to create a git clone folder
How to create a repository from media
How to create a wrapper that preserves the signature of the function to wrap
Verification of how to periodically execute a script on a Linux server on Windows
How to calculate the volatility of a brand
A simple example of how to use ArgumentParser
How to create a Python virtual environment (venv)
How to create a function object from a string
How to create explanatory variables and objective functions
How to create a JSON file in Python
How to create a shortcut command for LINUX
[Note] How to create a Ruby development environment
How to create a Kivy 1-line input box
How to set up a local development server
How to create a multi-platform app with kivy
How to create a Rest Api in Django
[Note] How to create a Mac development environment
How to put a lot of pipelines together and put them away at once
How to count the number of elements in Django and output to a template
How to apply updlock, rowlock, etc. with a combination of SQLAlchemy and SQLServer
Read the Python-Markdown source: How to create a parser
Create a dataset of images to use for learning
A memo of how to use AIST supercomputer ABCI
How to create a submenu with the [Blender] plugin
How to set up a VPN gateway to establish a connection between Alibaba Cloud and AWS
[GCF + Python] How to upload Excel to GCS and create a new table in BigQuery
[Go] How to create a custom error for Sentry
How to write a list / dictionary type of Python3
How to create a USB that Linux and Win10 installer and winpe can boot UEFI
A story of trial and error trying to create a dynamic user group in Slack
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Create a batch of images and inflate with ImageDataGenerator
How to create a local repository for Linux OS
[Python] How to create Correlation Matrix and Heat Map
Basics of PyTorch (2) -How to make a neural network-
Comparison of Windows Server and Free Linux to Commercial Linux
How to create a property of relations that can be prefetch_related by specific conditions
[Python] How to create a 2D histogram with Matplotlib
How to run Django on IIS on a Windows server
How to create a kubernetes pod from python code
HTTP server and HTTP client using Socket (+ web browser) --Python3
[Linux] [C / C ++] How to get the return address value of a function and the function name of the caller
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
How to create an instance of a particular class from dict using __new__ () in python
[Python] How to delete rows and columns in a table (list of drop method options)
I made a server with Python socket and ssl and tried to access it from a browser
[Python] How to create a table from list (basic operation of table creation / change of matrix name)