[PYTHON] Write a TCP server using the SocketServer module

Create using a convenient module for writing a server called SocketServer

#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-

import SocketServer

HOST = '127.0.0.1'
PORT = 8080

class Handler(SocketServer.StreamRequestHandler):
    def handle(self):
        while True:
            data = self.request.recv(1024)
            print data
            if len(data) == 0:
                break
            self.request.send(data)
        self.request.close()

server = SocketServer.TCPServer((HOST, PORT), Handler)
print 'listening', server.socket.getsockname()
server.serve_forever()

Recommended Posts

Write a TCP server using the SocketServer module
Write a super simple TCP server
Create a graph using the Sympy module
How to write a GUI using the maya command
Write data to KINTONE using the Python requests module
Try using the Python Cmd module
Notes on using matplotlib on the server
Write processing time measurement a little easier using the with clause
Easily build a DNS server using Twisted
Write the test in a python docstring
Set up a mail server using Twisted
Write a TCP client with Python Twisted
Install the python module with pip on a server without root privileges
Create a record with attachments in KINTONE using the Python requests module
Add a layer using the Keras backend
Save an array of numpy to a wav file using the wave module
Automatically write admin.py using the django-extensions admin_generator command
Easy to create API server using go-json-rest module
I tried using the Datetime module by Python
[Python] A rough understanding of the logging module
Use the e-paper module as a to-do list
Try using the collections module (ChainMap) of python3
Generate a hash value using the HMAC method.
Let's make a module for Python using SWIG
How to uninstall a module installed using setup.py
Prepare a pseudo API server using GitHub Actions
Create a GUI on the terminal using curses
A story that was convenient when I tried using the python ip address module
[Python] You can save an object to a file by using the pickle module.
The story of launching a Minecraft server from Discord
Get the file name in a folder using glob
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
Set up a file server on Ubuntu 20.04 using Samba
Creating a graph using the plotly button and slider
DJango Note: From the beginning (using a generic view)
Create a pseudo REST API server using GitHub Pages
Learning neural networks using Chainer-Creating a Web API server
Write a log-scale histogram on the x-axis in python
[Python] I tried running a local server using flask
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
How to create a simple TCP server / client script
[Python] Mask the image into a circle using Pillow
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
A little bit from Python using the Jenkins API
Create a dictionary by searching the table using sqlalchemy
Send a message from the server to your Chrome extension using Google Cloud Messaging for Chrome