Ho un problema con questi codici client e server, continuo a ricevere [Errno 10061] Impossibile stabilire una connessione perché il La macchina target lo ha attivamente rifiutatoErrno 10061: impossibile stabilire una connessione perché il computer di destinazione lo ha rifiutato attivamente (client - server)
Sto eseguendo il server su una macchina virtuale con Windows XP SP3 e il client su Windows 7 a 64 bit, la mia versione di Python è la 2.7.3. Quello che voglio sapere è come dovrei modificare il codice per usare il client e il server su reti diverse! Grazie!
server:
#!/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
cliente:
#!/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: il codice è da internet.
_attivamente rifiutato_ implica che il firewall della macchina server ha bloccato la connessione, probabilmente non correlato al codice. –
Il firewall è disattivato:/continua a ricevere l'errore – havox
In che modo il guest VM è connesso alla rete? Via NAT + Porta avanti o in modalità bridge? –