TCP-based socket: Links cycle

# Server must meet at least three things: 
# 1 binds a fixed ip and Port
# 2. external services has been stable operation
# 3 can support concurrent


#### this program can achieve functional cycle links, a an incoming provided semijoin pool size determines how many can come, a wait also come to a


### server application


from Socket Import *

Server Socket = (AF_INET, SOCK_STREAM)
server.bind (( '127.0 .0.1 ', 8081))
server.listen (. 5)

# links circulating
the while True:
Conn, client_addr = server.accept ()
Print (client_addr)

# communications cycle
the while True:
the try:
Data = conn.recv (1024)
IF len (data) == 0: break # linux system for
print ( '-> receiving the client message:', Data)
conn.send (data.upper ())
the except ConnectionResetError:
BREAK

conn.close()

server.close()

##客户端程序

from socket import *

client = socket(AF_INET, SOCK_STREAM)
client.connect(('127.0.0.1', 8081))

# 通信循环
while True:
msg=input('>>: ').strip() #msg=''
if len(msg) == 0:continue
client.send(msg.encode('utf-8')) #client.send(b'')
# print('has send')
data=client.recv(1024)
# print('has recv')
print(data)

client.close()

Guess you like

Origin www.cnblogs.com/1832921tongjieducn/p/11352496.html