Python 绑定套接字时出错
我正在编写一个服务器脚本,用于很多事情,如游戏、数据传输、聊天等 我的问题是我遇到了以下错误:Python 绑定套接字时出错,python,sockets,python-2.7,networking,server,Python,Sockets,Python 2.7,Networking,Server,我正在编写一个服务器脚本,用于很多事情,如游戏、数据传输、聊天等 我的问题是我遇到了以下错误: Traceback (most recent call last): File "server.py", line 11, in <module> s.bind((host, port)) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) TypeErr
Traceback (most recent call last):
File "server.py", line 11, in <module>
s.bind((host, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
TypeError: an integer is required
端口应为整型。将线路端口='5002'更改为端口=5002哦,天哪,我怎么会错过它,我不敢相信自己。非常感谢你!
#!/usr/bin/python
# This is server file
import socket
# server & connection settings
host = '127.0.0.1'
port = '5002'
s = socket.socket() # Creating socket object
s.bind((host, port))
s.listen(10)
# server & connection settings
while True:
c,addr = s.accept() # Establish connection with clients.
print 'Got connection from ', addr # Print ip adress of the recently connected client.
c.send('You succesfully established connection with our servers.') # Send socket to the client.
print 'Socket had been sent to the client: ', addr # Print to the server console that we succesfully established connection with the client
c.close() # Close the client connection. Bye, bye! /// Will delete this part when the time come