Python Forum

Full Version: No connection could be made becouse the target machine actively refused it.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to establish a connection between 2 diffrent mechies.

heres my code
server:
#!/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 = 14321             # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

s.listen(5)
while True:
   c, addr = s.accept()     # Establish connection with client.
   print ("Got connection from", addr)
   msg = input("what do you want to send?\n")
   c.send(msg)

client:

#!/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 = 14321 # Reserve a port for your service.
while True: 
    s.connect((host, port)) 
    print (s.recv(1024))
HEEEELP
it says No connection could be made becouse the target machine actively refused it.
what?
iv tryed a vpn btw... and it still desent work?
help?
It may be looking for user agent, but there are many reasons why connection may be refused.
At any rate you can explore the guide here: https://www.w3.org/Protocols/rfc2616/rfc2616.html