如何解决Python Sockets/SocketServer连接[Errno 10048]和[Errno 10049]?

问题描述 投票:0回答:1

我正在尝试制作一款在线 FPS 游戏,到目前为止它可以在我的本地网络上运行。我想做的是让它在全球范围内发挥作用

我过去曾尝试过让其他 Python 项目在全球范围内运行,但到目前为止我还无法让它运行。我从 ipchicken 或其他什么地方获取我的 IP,并将其作为服务器的主机,但是当我尝试启动它时,我得到了这个。

socket.error: [Errno 10049] The requested address is not valid in its context

我尝试了从不同地方找到的可能是我的 IP 地址的许多不同版本,但它们都给出了该输出。

我想,既然我有了自己的网络空间,我就可以尝试做 Python 手册中所说的事情:

其中 host 是一个字符串,表示互联网域表示法中的主机名,例如“daring.cwi.nl”

因此,我输入了我的网络空间的域名 (

h4rtland.p3dp.com
),然后收到此错误:

socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

虽然只在端口 80 上,但其他任何东西都会给我带来与以前相同的错误。

如果有人能为我阐明这个主题,我将不胜感激。

python sockets ip ip-address
1个回答
2
投票

首先,端口 80 通常是 http 流量。端口 5000 下的任何内容都是特权的,这意味着您真的不想将服务器分配给此端口,除非您“绝对”知道自己在做什么...以下是设置服务器套接字以接受侦听的简单方法。 . import socket host = None #will determine your available interfaces and assign this dynamically port = 5001 #just choose a number > 5000 for socket_information in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM): (family, type, prototype, name, socket_address) = socket_information sock = socket.socket(family, type, prototype) sock.bind(socket_address) max_clients = 1 sock.listen(max_clients) connection, address = sock.accept() print 'Client has connected:', address connection.send('Goodbye!') connection.close()

这是一个 TCP 连接,对于 FPS 游戏,您可能希望考虑使用 UDP,这样丢包就不会严重影响性能...祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.