50 lines
917 B
Python
50 lines
917 B
Python
import socket
|
|
import threading
|
|
|
|
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
|
|
|
ip = input('ip: ')
|
|
#ip='www.ggsya.ga'
|
|
#ip = '41.40.24.151'
|
|
#ip = socket.getaddrinfo('ggsya.ga',9000)[0][-1]
|
|
print('trying to connect')
|
|
clientsocket.connect((ip,9000))
|
|
print('connected')
|
|
name = input('name: ')
|
|
clientsocket.send(name.encode())
|
|
for i in name:
|
|
try:
|
|
int(i)
|
|
print('there is a number in de name?!?!')
|
|
except:
|
|
pass
|
|
|
|
def recievemessage():
|
|
while True:
|
|
try:
|
|
incoming_message =clientsocket.recv(1024) # try to receive 1024 bytes
|
|
except socket.timeout:
|
|
pass
|
|
else:
|
|
print(incoming_message.decode())
|
|
|
|
|
|
|
|
|
|
def sendmessage():
|
|
while 1:
|
|
message = input()
|
|
clientsocket.send(message.encode())
|
|
|
|
|
|
clientsocket.settimeout(0.1)
|
|
|
|
thread = threading.Thread(target=recievemessage)
|
|
thread.start()
|
|
|
|
sendmessage()
|
|
|
|
|