Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- клиенскый код часть написан на python2.7
- #-*-coding:utf8;-*-
- from socket import *
- HOST=''
- PORT = 9091
- ADDR = (HOST, PORT)
- tcpCliSock = socket (AF_INET, SOCK_STREAM)
- print("[Режим ожидание....]")
- while True:
- try:
- tcpCliSock.connect(ADDR)
- except Exception:
- continue
- print(tcpCliSock.recv(1024))
- print("\n")
- while True:
- inp = raw_input ('==>')
- if str(0)<inp:
- if not inp:
- break
- tcpCliSock.send(inp)
- print(tcpCliSock.recv(1024))
- tcpCliSock.close()
- Сераерный код на python3
- #-*-coding:utf8;-*-
- from socket import *
- import subprocess
- import time
- import sys, os
- def times():
- tim=time.ctime()
- return tim
- host = ""
- port = 9091
- ADDR=(host, port)
- tcp=socket(AF_INET, SOCK_STREAM)
- tcp.bind(ADDR)
- tcp.listen(1)
- print("start server. host")
- print("-"*31)
- while True:
- tcpCli, addr=tcp.accept()
- print("client connected with address\n", addr)
- tcpCli.send("[+] Сервер Готов". encode('utf-8'))
- while True:
- data=tcpCli.recv(1024)
- print(data)
- if data.decode('utf-8')=="time":
- response = '[+]' % times()
- tcpCli.send(response.encode('utf-8'))
- else:
- tcpCli.send(data.encode('utf-8'))
- break
- tcpCli.close()
- tcp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement