#!/usr/bin/python
 
import socket

HOST = "127.0.0.1"
PORT = 9998

try:
    mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mysocket.connect((HOST, PORT))
    print('Połączony z serwerem ' + str(HOST) + ' na porcie ' + str(PORT))
    message = mysocket.recv(1024)
    print("Dane odebrane z serwera:", message)
    while True:
        message = input("Wpisz komunikat > ")
        mysocket.send(bytes(message.encode('utf-8')))
        if message== "koniec":
            break
except socket.errno as error:
    print("Błąd gniazda", error)
finally:
    mysocket.close()