title: Socket Server in Python
body: <p>I am trying to set up a local server so that other PCs on the same local network can connect to it. When trying to do so, on the client side, I get the following error:
   [Errno 10061] No connection could be made because the target machine actively refused it</p>
  
  <p>I have been searching around for hours and still couldn't resolve this issue. I tried turning off my Firewall too, but nothing.</p>
  
  <p>These are my server and client codes:</p>
  
  <p>Server Code:</p>
  
  <pre><code>import socket
  import threading
  import SocketServer
  import datetime
  
  ver_codes = []
  
  
  
  class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
      def handle(self):
          print threading.current_thread().isDaemon()
          data = self.request.recv(1024)
          command = data.split()[0]
          if(command=="login"):
              if(logged_in(data.split()[1])==False):
                  self.request.sendall(login(data.split()[1], data.split()[2]))
              else:
                  self.request.sendall("already in")
  
  
  class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
      pass
  
  def client(ip, port, message):
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.connect((ip, port))
      try:
          sock.sendall(message)
          response = sock.recv(1024)
          print "Received: {}".format(response)
      finally:
          sock.close()
  
  def logged_in(id_num):
      for i in ver_codes:
          if(i[0]==id_num):
              return True
      return False
  
  def login(username, password):
      login_file = open("Login.txt", "r")
      match = login_file.readline()
      while(match!="*"):
          if(match.split()[0]==username):
              if(match.split()[1]==password):
                  ver_codes.append([match.split()[0], encryption_code(match.split()[2])])
                  login_file.close()
                  return "{} {}".format(match.split()[2], encryption_code(match.split()[2]))
                  print "And Here"
          match = login_file.readline()
      return "Denied"
      login_file.close()
  
  def encryption_code(to_encrypt):
      now = datetime.datetime.now()
      return int(str(now.microsecond)) * int(to_encrypt)
  
  
  if __name__ == "__main__":
  HOST, PORT = "localhost", 7274
  
  server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
  ip, port = server.server_address
  print server.server_address
  
  server_thread = threading.Thread(target=server.serve_forever)
  server_thread.daemon = False
  server_thread.start()
  print "Server loop running in thread:", server_thread.name
  </code></pre>
  
  <p>Client Code:</p>
  
  <pre><code>import socket
  import sys
  
  HOST, PORT = "localhost", 7274
  data = " ".join(sys.argv[1:])
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  try:
  sock.connect((HOST, PORT))
  sock.sendall("login mahdiNolan m1373")
  
  received = sock.recv(1024)
  finally:
  sock.close()
  </code></pre>
  
  <p>I really appreciate any help you could give me!
  Thanks A LOT beforehand!</p>