如何解决Python Sockets/SocketServer连接[Errno 10048]& [错误号10049]?

发布于 2024-12-01 00:47:20 字数 753 浏览 0 评论 0原文

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

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

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

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

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

其中 host 是一个字符串,表示采用 Internet 域表示法(如“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 上,但其他任何东西都会给我带来与以前相同的错误。

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

I'm trying to make an online FPS game and so far it works on my local network. What I'm trying to do is make it work globally

I've tried making other Python projects work globally in the past but so far I haven't been able to get it to work. I get my IP from ipchicken or whatever and put it as the HOST for the server, but when I try to start it I get this.

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

I've tried many different versions of what could be my IP address found from various different places, but all of them give that output.

I thought, since I had my webspace, I could try doing what it says you can do in the Python manual:

where host is a string representing either a hostname in Internet domain notation like 'daring.cwi.nl'

So, I put in the domain of my webspace (h4rtland.p3dp.com) and I get this error:

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

Though only on port 80, anything else gives me the same error as before.

If anybody can shed some light on this subject for me it would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2024-12-08 00:47:20

首先,端口 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 来研究,这样丢弃的数据包不会严重影响性能...祝你好运

First off, port 80 is typically http traffic. Anything under port 5000 is priviledged which means you really don't want to assign your server to this port unless you absolutely know what you are doing... Following is a simple way to set up a server socket to accept listen...

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()

This is a TCP connection, for an FPS game you likely want to look into using UDP such that dropped packets don't impact performance terribly... Goodluck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文