我写了一个小的python脚本来建立到服务器的一定数量的连接。这可以正常工作,但是我可以在数据包捕获中看到服务器正在发送FIN并在接收到数据后关闭连接,这可以避免。我想保持连接打开状态直到关闭它?
def create_socket(COUNT):
sock = socket.socket()
host = '1.2.3.4'
port = port
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host,port))
sock.send(str.encode("Connection " + str(COUNT) + " connected successfully"))
return sock
if __name__ == '__main__':
try:
while ATTEMPTS > 0:
server_sock = create_socket(COUNT)
print("Connection attempt " + str(COUNT))
socket_list.append(server_sock)
ATTEMPTS -= 1
COUNT += 1
except:
RESPONSE = 'Failed, unable to connect'
finally:
print(RESPONSE)
print("Waiting 15 seconds before closing all connections")
time.sleep(15)
server_sock.close()