How to solve Python Sockets/SocketServer Connection [Errno 10048] & [Errno 10049]?

谁说胖子不能爱 提交于 2019-12-22 11:44:23

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/7162869/how-to-solve-python-sockets-socketserver-connection-errno-10048-errno-10049

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!