-
Notifications
You must be signed in to change notification settings - Fork 0
/
soc_ket.py
33 lines (25 loc) · 852 Bytes
/
soc_ket.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
import socket as s
import sys
import upload as u
class Exchange:
def receive(self, host='0.0.0.0'):
PORT_NUMBER = 7899
SIZE = 1024
try:
host = s.gethostbyname(host)
except:
pass
mySocket = s.socket(s.AF_INET, s.SOCK_DGRAM)
mySocket.bind((host, PORT_NUMBER))
(data, addr) = mySocket.recvfrom(SIZE)
data=data.decode('utf-8')
downloader = u.TransferData()
downloader.download_file(data)
def send(self, server, link):
SERVER_IP = server
PORT_NUMBER = 7899
SIZE = 1024
print("Test client sending packets to IP {0}, via port {1}\n".format(
SERVER_IP, PORT_NUMBER))
mySocket = s.socket(s.AF_INET, s.SOCK_DGRAM)
mySocket.sendto(link.encode('utf-8'), (SERVER_IP, PORT_NUMBER))