Write a super simple TCP server

The server has the following processing flow.

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

import socket

HOST = '127.0.0.1'
PORT = 8080

#Creating a socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

#Association of sockets and IP addresses
s.bind((HOST, PORT))

#Preparing to connect with the client
s.listen(1)

#Connection with client
conn, addr = s.accept()

print 'Connected by', addr

#Receive data from client
#Send data to client
while True:
    data = conn.recv(1024)
    if len(data) == 0:
        break
    conn.send(data)

conn.close()

Recommended Posts

Write a super simple TCP server
Write a TCP server using the SocketServer module
Create a (simple) REST server
Create a simple textlint server
Write a super simple molecular dynamics program in python
Let's write a simple DC current solver
Build a simple WebDAV server on Linux
Write a simple greedy algorithm in Python
Write a TCP client with Python Twisted
Write a simple Vim Plugin in Python 3
Set up a simple HTTPS server in Python 3
Set up a simple HTTPS server with asyncio
Set up a simple SMTP server in Python
A simple Python HTTP server that supports Range Requests
Super simple: A collection of shells that output dates
[Vagrant] Set up a simple API server with python
It's hard to write a very simple algorithm in php
Super simple! centos7, sendmail in local environment, DNS server construction
A simple sample of pivot_table.
A super introduction to Linux
Read and write a file
What is a super user?
Write and read a file
Let's write a simple simulation program for the "Monty Hall problem"