Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2018
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. клиенскый код часть написан на python2.7
  2.  
  3. #-*-coding:utf8;-*-
  4. from socket import *
  5.  
  6. HOST=''
  7. PORT = 9091
  8. ADDR = (HOST, PORT)
  9.  
  10. tcpCliSock = socket (AF_INET, SOCK_STREAM)
  11. print("[Режим ожидание....]")
  12. while True:
  13.      try:
  14.         tcpCliSock.connect(ADDR)
  15.     except Exception:
  16.           continue
  17.     print(tcpCliSock.recv(1024))
  18.     print("\n")
  19.  
  20.     while True:
  21.          inp = raw_input ('==>')
  22.          if str(0)<inp:
  23.             if not inp:
  24.                break
  25.             tcpCliSock.send(inp)
  26.            print(tcpCliSock.recv(1024))
  27.  
  28. tcpCliSock.close()
  29.  
  30. Сераерный код на python3
  31. #-*-coding:utf8;-*-
  32.  
  33. from socket import *
  34. import subprocess
  35. import time
  36. import sys, os
  37.  
  38. def times():
  39.    tim=time.ctime()
  40.    return tim
  41.  
  42. host = ""
  43. port = 9091
  44. ADDR=(host, port)
  45.  
  46. tcp=socket(AF_INET, SOCK_STREAM)
  47. tcp.bind(ADDR)
  48. tcp.listen(1)
  49. print("start server. host")
  50. print("-"*31)
  51.  
  52. while True:
  53.      tcpCli, addr=tcp.accept()
  54.      print("client connected with address\n", addr)
  55.      tcpCli.send("[+] Сервер Готов". encode('utf-8'))
  56.      while True:
  57.          data=tcpCli.recv(1024)
  58.          print(data)
  59.          if data.decode('utf-8')=="time":
  60.             response = '[+]' % times()
  61.             tcpCli.send(response.encode('utf-8'))
  62.         else:
  63.            tcpCli.send(data.encode('utf-8'))
  64.            break
  65.  
  66.        tcpCli.close()
  67. tcp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement