将Python SSL客户端连接到SSL套接字服务器

时间:2020-04-17 08:59:54

标签: python-3.x sockets ssl

我正在尝试建立从本地计算机到我之前购买的服务器的ssl连接,该服务器也已购买了ssl证书。 我正在尝试将客户端(我的计算机)连接到服务器,但它只会给我一个错误:

这是我的代码:

服务器:

ItemNumber:123456, OptionNumber:123, Count:2
ItemNumber:123456, OptionNumber:126, Count:4
ItemNumber:112233, OptionNumber:111, Count:1
ItemNumber:112244, OptionNumber:222, Count:4

客户端:

import socket
import ssl

port = 7000
host = " "   #thats where the servers ip adress would be
s = socket.socket()
s = ssl.wrap_socket(s, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True)
s.bind((host, port))
s.listen(3)
print("waiting for connection")

while True:
    c, addr = s.accept()
    print("Connected,", addr)

s.close()

错误:

import ssl
import socket

host = " " #thats where the servers ip adress would be
port = 7000
c = socket.socket()
c = ssl.wrap_socket(c, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True)

c.connect((host, port))

c.close()

我多次检查以确保IP和端口号相同,并且该端口在我的服务器上可用。

0 个答案:

没有答案