【发布时间】:2014-04-22 22:50:49
【问题描述】:
我喜欢有一个端口首先用于连接到另一台服务器,然后此端口用作服务器,其他客户端连接到它。
我将python套接字用于客户端,现在我想将它用于服务器套接字。
我的代码:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12349
portt = 12341 # Reserve a port for your service.
s.bind((host, portt)) # Bind to the port
s.connect((host, port))
s.listen(5) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
print c
print 'Got connection from', addr
print s.recv(1024)
s.close
输出是
Traceback (most recent call last):
File "client.py", line 12, in <module>
s.listen(5) # Now wait for client connection.
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument
我该怎么做。 谢谢你的回答!
【问题讨论】:
标签: python sockets networking