python套接字错误[winError 10049

时间:2018-07-07 13:14:14

标签: python windows sockets

我一直试图让我的程序在在线客户端上运行。我在计算机上尝试了该程序,出于某种奇怪的原因,它似乎在底部说了错误。

这是我的服务器代码:

import socket  #for sockets
import sys  #for exit
import time
s = socket.socket()
print('Socket Created')
port = 6665
host = '172.18.0.82'
host1 = socket.gethostbyname(socket.gethostname())
print("hostname is: " + str(socket.gethostname()))

ip = socket.gethostbyname(host)
print("ip is:" + host1)
try:
    remote_ip = socket.gethostbyname(host)

except socket.gaierror:
    #could not resolve
    print('Hostname could not be resolved. Exiting')

s.bind((host1, port))
print("")
print("server is waiting for conection")

usernames = []
ids = []
#message


while True:
    s.listen(5)
    conn,addr = s.accept()
    print(addr+ "has connected to the server")
    current_msg_list = []
    incoming_message = conn.recv(1024)
    incoming_message.decode()

这是我的客户代码:

#imports
import socket
import sys
import time
#init
s = socket.socket()
time.sleep(1)
host = '10.0.0.66'

#host = input("what is the ip of the server?")
ip = socket.gethostbyname(host)
port = 6666
time.sleep(1)
try:
    s.connect(('0.0.0.0',port))
    print("connected!")
except socket.error as e:
    print(str(e))

这是弹出的错误:

[WinError 10049] The requested address is not valid in its context

0 个答案:

没有答案