これらのクライアントとサーバーコードに問題があります。[Errno 10061]ターゲットマシンが積極的にそれを拒否しましたErrno 10061:ターゲットマシンが積極的にそれを拒否したために接続できませんでした(クライアント - サーバー)
Windows XP SP3の仮想マシンとWindows 7 64bitのクライアントでサーバーを実行していますが、私のpythonバージョンは2.7.3です。私が知りたいことは、クライアントとサーバーを異なるネットワーク上で使用するためにコードを編集する必要があることです。ありがとう!
サーバー:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = '0.0.0.0' # Get local machine name
port = 12345 # Reserve a port for your service.
print 'Server started!'
print 'Waiting for clients...'
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
while True:
msg = c.recv(1024)
print addr, ' >> ', msg
msg = raw_input('SERVER >> ')
c.send(msg);
#c.close() # Close the connection
クライアント:
#!/usr/bin/python # This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
print 'Connecting to ', host, port
s.connect((host, port))
while True:
msg = raw_input('CLIENT >> ')
s.send(msg)
msg = s.recv(1024)
print 'SERVER >> ', msg
#s.close # Close the socket when done
PS:コードは、インターネットからです。
これは、サーバーマシンのファイアウォールがおそらくコードと無関係な接続をブロックしたことを意味します。 –
ファイアウォールがオフ:/まだエラーが発生しています – havox
VMゲストはどのようにネットワークに接続されていますか? NAT +ポート経由またはブリッジモード経由ですか? –