python socketserver最大连接_如何解决Python套接字/ SocketServer连接[Errno 10048]& [Errno 10049]?...

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.

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值