title: Locking another computer using sockets without interrupting the connection
body: <p>I am trying to set up a server that can send each client - commands.<br>
  One command is 'lock' which locks the screen of the client.<br>
  When a client gets the word "lock" it runs this code on the client:  </p>
  
  <pre><code>import ctypes
  ctypes.windll.user32.LockWorkStation()
  </code></pre>
  
  <p>This code does lock the screen however- it ends my connection with the client..<br>
  How can I make the client stay connected but still locked? </p>
  
  <p>Note: The locking is not forever! it is only once, like putting the client's computer in sleep mode until he wants to unlock the screen.</p>
  
  <p>Hope I was clear enough. Thanks for helping! </p>
  
  <p>Server:</p>
  
  <pre><code>import socket
  
  def main():
  
      sock = socket.socket()
      sock.bind(('0.0.0.0', 4582))
      print("Waiting for connections...")
      sock.listen(1)
      conn, addr = sock.accept()
      print ("New connection from: ", addr)
  
      while 1:
          command = input("Enter command&gt; ")
  
  
          if command == 'shutdown':
              sock.send(b'shutdown')
          elif command == 'lock':
              sock.send(b'lock')
          else:
              print ("Unknown command")
  
          data = sock.recv(1024)
          print (data)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>import socket
  import ctypes
  
  
  def main():
  
      sock = socket.socket()
      sock.connect(('127.0.0.1', 4582))
  
  
      while 1:
  
          data = sock.recv(1024)
          print (data)
  
          if data == 'lock':
              sock.send(b'locking')
              ctypes.windll.user32.LockWorkStation()
  
          sock.recv(1024)
  
  
  if __name__ == '__main__':
      main()
  </code></pre>