问题描述
我正在尝试制作在线FPS游戏,到目前为止它可以在我的本地网络上运行。我要做的是让它在全球范围内工作
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
我过去曾试图让其他Python项目在全球范围内运作,但到目前为止我还没有能够让它工作。我从ipchicken或其他任何地方获取我的IP并将其作为服务器的HOST,但是当我尝试启动它时,我得到了这个。
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我尝试了很多不同版本的可能是我在不同地方找到的IP地址,但是所有这些版本都提供了输出。
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.
我想,因为我有我的网站空间,我可以尝试做它在Python手册中可以做的事情:
I thought, since I had my webspace, I could try doing what it says you can do in the Python manual:
所以,我放入了我的网站空间域( h4rtland .p3dp.com
)我收到此错误:
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
虽然仅在80号港口,任何地方ng else给了我与以前相同的错误。
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.
推荐答案
首先,端口80通常是http流量。端口5000下的任何东西都是特权的,这意味着你真的不想将服务器分配给这个端口,除非你绝对知道你在做什么......以下是设置服务器套接字的简单方法接受听...
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()
这是一个TCP连接,对于你可能想要使用UDP查看的FPS游戏,这样丢弃的数据包不会影响性能...... Goodluck
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
这篇关于如何解决Python套接字/ SocketServer连接[Errno 10048]& [Errno 10049]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!