-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTAREA1_karauz_dazofeifa_Sevidor.py
62 lines (51 loc) · 1.46 KB
/
TAREA1_karauz_dazofeifa_Sevidor.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import socket
import TAREA1_karauz_dazofeifa_Cliente
def decoMsg(msg):
i = 0
j = 0
d = [4,8,3]
b = ""
c = ""
flag = True
msg = msg + "/"
c2 = 0
while flag:
c = msg[i]
if c == "/":
flag = False
return b
if c >= chr(65) and c <= chr(90):
c2 = ord(c)
c2 -= d[j]
c = chr(c2)
if c < chr(65):
c2 = ord(c)
c2 = c2 - 64 + 90
c = chr(c2)
elif c == chr(126):
c = chr(32)
b += c
i += 1
if j < 2:
j += 1
else:
j=0
def iniciarServidor(host, puerto):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, puerto))
s.listen(5) #hasta 5 peticiones
while True:
#establecer conexion
(c, addr) = s.accept()
print("Se establecio conexion con: %s" % str(addr))
msg = 'Conexion establecida con: %s' % socket.gethostname() + "\r\n"
c.send(msg.encode('utf8'))
msg_rec = c.recv(1024)
msg_rec = msg_rec.decode('ascii')
TAREA1_karauz_dazofeifa_Cliente.iniciarCliente("10.251.45.250",44440,TAREA1_karauz_dazofeifa_Cliente.codiMsg(decoMsg(msg_rec)))
print(decoMsg(msg_rec))
c.close
if __name__ == "__main__":
host = ""
puerto = 44440
iniciarServidor(host, puerto)