-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_sck.py
37 lines (29 loc) · 899 Bytes
/
client_sck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import socket
import os
import subprocess
import time
class client:
def __init__(self, host, port):
self.sck = None
self.host = host
self.port = port
print("Client object has been created!")
def create_socket(self):
self.sck = socket.socket()
def connect(self):
try:
self.create_socket()
self.sck.connect((self.host, self.port))
print(f"connected to the server {self.host} on port {self.port} successfully")
except Exception as e:
print(f"OOPS Something gone wrong! {e}. Retrying...")
time.sleep(3)
self.connect()
def receiveData(self):
while True:
data = self.sck.recv(2)
data_decoded = data.decode('utf-8')
print(data_decoded)
client1 = client("0.0.0.0", 9999)
client1.connect()
client1.receiveData()