title: python socket programming : error trying to connect to server
body: <p>I'm a beginner in python socket programming and I have to send a message from the server to the client side . I have 2 python IDLES one for the server and one for the client. I have made the server file with no errors but when I create a connection socket in my client file and try to connect to server I get the error: </p>
  
  <pre><code>clientSocket.connect((servername,port))
  ConnectionRefusedError: [WinError 10061] no connection could be made because the target machine actively refused it
  </code></pre>
  
  <p>I don't know how to deal with this error and I would appreciate your help with guiding me. 
  Thank you in advance. 
  My code: </p>
  
  <p>Server:</p>
  
  <pre><code>from socket import *
  
  port = 1234
  serverSocket = socket(AF_INET,SOCK_STREAM)
  serverSocket.bind(('',port))
  serverSocket.listen()
  print("Server has started")
  
  data = "Network labs"
  while True:
      connectionSocket , addr = serverSocket.accept()
      connectionSocket.send(data)
      connectionSocket.close()
  </code></pre>
  
  <p>Client: </p>
  
  <pre><code>from socket import *
  
  port = 1234
  servername = 'localhost'
  clientSocket = socket(AF_INET,SOCK_STREAM)
  clientSocket.connect((servername,port)) #this is where the error happens
  </code></pre>