02select listening client

Time:2021-10-21
#Coding: utf-8import socket # defines a message list. Messages = ['this is the message', 'it will be sent', 'in parts',]# defines a primitive to specify the server to be connected. server_ Address = ('localhost ', 8090) # create atcp / IP socket # initialize two sockets # connect the socket to the port where the server is listening # print out the IP and port to be connected # and then connect to the server# Connect to server for I in range (10): sockets = [socket.socket (socket. Af_inet, socket. Sock_stream), socket.socket (socket. Af_inet, socket. Sock_stream)] print ('connecting to% s port% s'% server_address) for s in sockets: Print (s) s.connect (server_address) # loop through to send message for index, message in enumerate (messages): # send messages on both sockets # traverse the defined sockets and send the defined messages. For s in sockets: Print ('% s: sending'% s'% (s.getsocket(), message + str (index))) s.send (bytes ((message + str (index)). Encode ('utf-8 ')) #Read responses on both sockets # to receive messages, for s in sockets: # loop to receive messages. Data = s.recv (1024) # print the received IP, port, and message. Print ('% s: received'% s'% (s.getsocket(), data)) if data! = "": Print ('closingsocket ', s.getsocket())             s.close()

Recommended Today

SQL statement of three-level linkage of provinces, cities and counties

The first is the table creation statement Copy codeThe code is as follows: CREATE TABLE `t_address_province` ( `id` INT AUTO_ Increment primary key comment ‘primary key’,`Code ` char (6) not null comment ‘province code’,`Name ` varchar (40) not null comment ‘province name’)Engine = InnoDB default charset = utf8 comment = ‘province information table’; CREATE TABLE […]