#!/usr/bin/python

import socket

SERVER_IP = "127.0.0.1"
SERVER_PORT = 9998

#  Rodzina adresów = Internet, typ = SOCK_STREAM, czyli protokół TCP.
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind((SERVER_IP, SERVER_PORT))

server.listen(5)

print("[*] Oczekiwanie na żądania na adresie i porcie %s:%d" % (SERVER_IP, SERVER_PORT))

client, addr = server.accept()

client.send("Witaj, tu serwer...".encode())

print("[*] Odebrane żądanie z %s:%d" % (addr[0], addr[1]))

def handle_client(client_socket):
    request = client_socket.recv(1024)
    print("[*] Odebrane dane : %s od klienta %s" % (request, client_socket.getpeername()))
    client_socket.send(bytes("ACK", "utf-8"))

while True:
    handle_client(client)

client_socket.close()
server.close()