0
私のコンピュータとサーバ(ubuntu)との間でTCP通信を行いたいと思います。socket.errorを解決するには:サーバと私のコンピュータでPythonで[Errno 10061]
サーバIPは203.246.114.176でポート30000は開いています。
次server.pyを実行しているサーバー:
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('localhost', 30000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
while True:
# Wait for a connection
print >>sys.stderr, 'waiting for a connection'
connection, client_address = sock.accept()
try:
print >>sys.stderr, 'connection from', client_address
# Receive the data in small chunks and retransmit it
while True:
data = connection.recv(16)
print >>sys.stderr, 'received "%s"' % data
if data:
print >>sys.stderr, 'sending data back to the client'
connection.sendall(data)
else:
print >>sys.stderr, 'no more data from', client_address
break
finally:
# Clean up the connection
connection.close()
そして、私のコンピュータはclient.pyているが:
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('203.246.114.176', 30000)
print >>sys.stderr, 'connecting to %s port %s' % server_address
sock.connect(server_address)
try:
# Send data
message = 'This is the message. It will be repeated.'
print >>sys.stderr, 'sending "%s"' % message
sock.sendall(message)
# Look for the response
amount_received = 0
amount_expected = len(message)
while amount_received < amount_expected:
data = sock.recv(16)
amount_received += len(data)
print >>sys.stderr, 'received "%s"' % data
finally:
print >>sys.stderr, 'closing socket'
sock.close()
私は、サーバーで実行すると、出力は次のようである:
starting up on localhost port 30000
waiting for a connection
となり、ufwのステータスは次のようになります。
To Action From
-- ------ ----
22 ALLOW Anywhere
5979/tcp ALLOW Anywhere
5901 ALLOW Anywhere
8080 ALLOW Anywhere
5978/tcp ALLOW Anywhere
5980/tcp ALLOW Anywhere
31415 ALLOW Anywhere
5981 ALLOW Anywhere
5982 ALLOW Anywhere
5983 ALLOW Anywhere
5984 ALLOW Anywhere
5985 ALLOW Anywhere
22/tcp ALLOW Anywhere
2222/tcp ALLOW Anywhere
77/tcp ALLOW Anywhere
21 ALLOW Anywhere
3306 ALLOW Anywhere
30000/tcp ALLOW Anywhere
30001/tcp ALLOW Anywhere
30002/tcp ALLOW Anywhere
30003/tcp ALLOW Anywhere
30004/tcp ALLOW Anywhere
30005/tcp ALLOW Anywhere
30006/tcp ALLOW Anywhere
30007/tcp ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
5979/tcp (v6) ALLOW Anywhere (v6)
5901 (v6) ALLOW Anywhere (v6)
8080 (v6) ALLOW Anywhere (v6)
5978/tcp (v6) ALLOW Anywhere (v6)
5980/tcp (v6) ALLOW Anywhere (v6)
31415 (v6) ALLOW Anywhere (v6)
5981 (v6) ALLOW Anywhere (v6)
5982 (v6) ALLOW Anywhere (v6)
5983 (v6) ALLOW Anywhere (v6)
5984 (v6) ALLOW Anywhere (v6)
5985 (v6) ALLOW Anywhere (v6)
22/tcp (v6) ALLOW Anywhere (v6)
2222/tcp (v6) ALLOW Anywhere (v6)
77/tcp (v6) ALLOW Anywhere (v6)
21 (v6) ALLOW Anywhere (v6)
3306 (v6) ALLOW Anywhere (v6)
30000/tcp (v6) ALLOW Anywhere (v6)
30001/tcp (v6) ALLOW Anywhere (v6)
30002/tcp (v6) ALLOW Anywhere (v6)
30003/tcp (v6) ALLOW Anywhere (v6)
30004/tcp (v6) ALLOW Anywhere (v6)
30005/tcp (v6) ALLOW Anywhere (v6)
30006/tcp (v6) ALLOW Anywhere (v6)
30007/tcp (v6) ALLOW Anywhere (v6)
しかし、私のコンピュータは、この出力を示しています。
C:\Users\user\Documents\notepad>python client.py
Traceback (most recent call last):
File "client.py", line 7, in <module>
s.connect((host, port))
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10061]
問題ですか?そして私はどうしたらいいですか?
ヘルプplz。
ありがとうございます! Urは非常に役立つことをお勧めします!!! –