我正在尝试在客户端和服务器之间创建连接,但我无法向其发送消息。
错误:" [WinError 10057]发送或接收数据的请求是 因为套接字没有连接而且(当发送时没有连接) 使用sendto调用的数据报套接字没有提供地址"
服务器端也没有错误,因为它认为它发送了消息。 似乎我无法从服务器向客户端发送任何消息,这些消息它们都可以工作,但是没有从客户端接收消息。
这是客户端功能:
def receiving(ip, port, serverNumber) :
while True :
try :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((ip , port))
s.listen(1)
print('waiting ...')
conn, add = s.accept()
print('connected')
string = ''
while True :
print('starting to receive data')
string += s.recv(2048).decode()
print(string)
if 'OVER' in string :
break
while True :
try :
string = string.replace("OVER","")
Connections.MessageTranslator(string,serverNumber)
print('data has received :', datetime.datetime.now())
break
except Exception as error :
print(str(error))
except Exception as error :
print(str(error))
这是我的服务器功能:
def server_sender() :
while True :
while True :
try :
port = Connections.SenderPortGetter()
ip = Connections.ClientIpGetter()
ip = ip.replace(" ","")
ip = ip.replace("\n","")
ip = ip.replace("\t","")
break
except Exception as error :
print(str(error))
while True :
try :
Message = Connections.MessageGetter()
Message = Connections.InfoExtractor(Message, 100)
############################
while True :
try :
print('here')
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect((ip , port))
break
except Exception as error :
print(str(error))
############################
i = 0
while i < len(Message) :
s.send(str.encode(Message[i]))
i += 1
while True :
try :
i = 0
string = ''
while i < len(Message) :
string += Message[i]
i += 1
print('problem is here')
string = string.replace("OVER","")
Connections.OldFilesFolderUpdat(string)
break
except Exception as error :
print(error)
break
####
except Exception as error :
print('Big fat error :', str(error))