Advertisement
Korotkodul

server.py

Sep 10th, 2022 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. import socket
  2. sock = socket.socket()
  3. sock.bind(('10.8.128.183',9991))
  4. sock.listen(3)
  5. A, addrA = sock.accept()
  6. B, addrB = sock.accept()
  7. A.send(b"x")
  8. B.send(b"0")
  9. #A.send(b"Hello!")
  10. #B.send(b"Hello!")
  11.  
  12. cnt = -1
  13. while True:
  14.     cnt = (cnt + 1) % 2
  15.     to = A#ходит B
  16.     from_who = B
  17.     if cnt == 0:#ходит A
  18.         to = B
  19.         from_who = A
  20.         #x=0
  21.     #to.send(b"Write smth")
  22.     data = from_who.recv(1024)
  23.     if not data:
  24.         break
  25.     elif data == b"end":
  26.         A.send(b"end")
  27.         break
  28.  
  29.     #print(b"from CLIENT ")
  30.     #print(data)
  31.     #print()
  32.     #message = bytes(input(), 'utf-8')
  33.     to.send(data)
  34.  
  35. #str = bytes(s, 'utf-8')
  36. A.close()
  37. B.colse()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement