绑定套接字时出错

时间:2015-01-21 12:42:39

标签: 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)
TypeError: an integer is required

到目前为止,我处于服务器脚本的开头,之前我编写了许多网络脚本。不应该有任何问题。我在我的本地和我的服务器上尝试了这个脚本,但仍然是相同的错误和完全相同的错误。我真的很感激任何帮助。

这是我的代码:

#!/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

0 个答案:

没有答案