简体   繁体   English

不允许发送数据? [Win 错误 10057]

[英]Data send disallowed? [WinError 10057]

I know this is an error on the server part where the s variable is being used when the conn variable should be used but I've been sitting here for 2 hours and cant see the mistake.我知道这是服务器部分的错误,当应该使用conn变量时正在使用s变量,但我已经在这里坐了 2 个小时,看不到错误。 The error: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied My code:错误: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied我的代码:

import socket
from _thread import *

server = '123.456.78.9'
port = 5555


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.bind((server, port))
except socket.error as e:
    str(e)
    
s.listen()
print("Waiting for connections, server has been started")

def threaded_client(conn):
    reply = ""
    conn.sendall(str.encode("[Server, Server]Mis:200:Connected"))
    while True:
        try:
            data = conn.recv(2048)
            reply = data.decode("utf-8")
            
            if not data:
                print("Disconnected from", addr[0])
                break
            
            print("Received: ", reply)
            print("Sending: ", reply)  
            conn.sendall(str.encode(reply))
        except:
            break
    print("Connection to", addr[0], "has been lost!")
    conn.close()

while True:
    conn, addr = s.accept()
    banlist = open('bannedip.bipf')
    if addr[0] in banlist.read():
        conn.sendall(str.encode("[Server, Server]Err:401:Banned"))
        conn.close()
        print("Banned ip", addr[0], ", was disconnected as their ip (", addr[0], ") is listed in the ban file")
    else:
        print("Connected to:", addr[0])
        start_new_thread(threaded_client, (conn,))```

I figured it out!我想到了! According to other people's [WinError 10057] problems its the server refusing to use a certain sock variable.根据其他人的[WinError 10057]问题是服务器拒绝使用某个 sock 变量。 Its been like 6 hrs and i decided to check my client code and it turns out that I first declared the client variable to be a normal socket in the __init__ function.已经过了 6 小时,我决定检查我的客户端代码,结果发现我首先在__init__ function 中将client变量声明为普通套接字。 Then in my connect function takes this variable and modifies it to be a connected variable (so send and recv functions work in that function).然后在我的connect function 中获取此变量并将其修改为连接变量(因此 send 和 recv 函数在该函数中工作)。 Then my send function re-reads the original socket (non-connection) and uses that to send (which fails).So i did the very complicated equivalent version (in server words) of doing conn, addr = s.accept() then making old_s = s then s = conn then stupidly resetting conn = old_s.然后我的发送 function 重新读取原始套接字(非连接)并使用它发送(失败)。所以我做了非常复杂的等效版本(用服务器的话)做conn, addr = s.accept()然后使old_s = s然后 s = conn 然后愚蠢地重置 conn = old_s。 That's the best I can explain it i'm sorry if you didn't understand a word of it.这是我能解释的最好的了,如果你一个字都没听懂,我很抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WinError 10057 不允许发送或接收数据的请求 - WinError 10057 A request to send or receive data was disallowed Python Socket SSL OSError:[WinError 10057] 发送或接收数据的请求被禁止,因为套接字未连接并且(wh - Python Socket SSL OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (wh Python 套接字库:OSError:[WinError 10057] 发送或接收数据的请求被禁止,因为套接字未连接 - Python socket library: OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected OSError: [WinError 10057] - OSError: [WinError 10057] Python 套接字 [WinError 10057]? - Python socket [WinError 10057]? 如何使用 PIR 传感器将信息从客户端发送到服务器端 [WinError 10057] - How can I send information from client side to server side using PIR-sensor [WinError 10057] Python 套接字模块错误:WinError 10057 - Python Socket Module Error: WinError 10057 Python 套接字通过以太网电缆连接提供 [WinError 10057] - Python socket gives [WinError 10057] with Ethernet cable connection 在我的 python 多人游戏中获取 [WinError 10057](使用 pygame) - Getting an [WinError 10057] in my python multiplayer game (using pygame) 我的 Python 套接字程序有问题 [WinError 10057] - I'm having a problem with my Python socket program [WinError 10057]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM