Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. from socket import *
  3. import time
  4. import sys
  5.  
  6. host="indirizzo ip server"
  7. port=5000
  8. remote = (host,port)
  9. print
  10. print  
  11. sock=socket(AF_INET,SOCK_STREAM)
  12. sock.connect(remote)
  13. print "Connessione stabilita con: %s, sulla porta %d" %remote
  14. def azione(sock):
  15.     command=raw_input("Comando: ")
  16.     if command == "exit":
  17.         sock.send(command)
  18.         sock.close()
  19.         del sock
  20.         exit()
  21.     else:
  22.         sock.send(command)  
  23.         ricevuto = sock.recv(1024)
  24.         if not ricevuto:
  25.             pass
  26.         else:
  27.             print ricevuto
  28.             azione(sock)
  29.  
  30.        
  31.  
  32. try:
  33.     azione(sock)
  34. except:
  35.     sock.close()
  36.     del sock
  37.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement