import socket
import time
HOST = ''
PORT = 12456
ADDR = (HOST, PORT)
bufferSize = 1024
tcpServerSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpServerSock.bind(ADDR)
tcpServerSock.listen(5)
while True:
print 'waiting for connection...'
tcpClientSock, addr = tcpServerSock.accept()
print 'connected from:', addr
while True:
data = tcpClientSock.recv(bufferSize)
if not data:
break
data = str.upper(data)
tcpClientSock.send('[%s] %s' % (time.ctime(), data))
tcpClientSock.close()
tcpServerSock.close()
Python网络编程---TCP Server
最新推荐文章于 2024-07-12 17:26:39 发布