2011-08-23 141 views
2

我正在尝试制作一个在线FPS游戏,目前它在我的本地网络上运行。我想要做的是让它全球工作如何解决Python套接字/套接字服务器连接[Errno 10048]&[Errno 10049]?

我试过让其他Python项目在过去的全球工作,但到目前为止,我还没有能够得到它的工作。我从ipchicken或其他任何地方获得我的IP,并将其作为服务器的主机,但是当我尝试启动它时,我得到了它。

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

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

我想,因为我有我的网站空间,我可以尝试做什么,它说,你可以在Python手工做:

where host is a string representing either a hostname in Internet domain notation like '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上,其他任何东西都会给我以前的错误。

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

+1

,你得到一个不同的原因端口80的错误是某些东西(可能是您的Web服务器)已经在使用它。 “从ipchicken或其他方面获得我的IP”是什么意思? – ghostJago

+0

尝试使用'localhost'作为您的地址。它工作吗? – 9000

回答

2

首先,端口80通常是http流量。在端口5000下的任何东西都是特权的,这意味着你真的不想把服务器分配给这个端口,除非你知道你正在做什么 ......以下是设置服务器套接字以接受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游戏...古德勒克

+2

端口1024下的任何端口号的权限不会低于5000 – cobie