Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 绑定套接字时出错_Python_Sockets_Python 2.7_Networking_Server - Fatal编程技术网

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