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