SHARE
TWEET

Client-prob6

Leonard_M Oct 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2. import struct
  3.  
  4. HOST = "192.168.43.4"
  5. PORT = 19999
  6.  
  7. string = "hello there"
  8. string = list(string)
  9. char = "e"
  10. positions = []
  11.  
  12. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
  13.     sock.connect((HOST, PORT))
  14.     sock.send(struct.pack("!I", len(string)))
  15.     sock.send(struct.pack("!c", char.encode('ascii')))
  16.  
  17.     for i in range(len(string)):
  18.         sock.send(struct.pack("!c", string[i].encode('ascii')))
  19.  
  20.     data = sock.recv(4)
  21.     data = struct.unpack("!I", data)[0]
  22.     print("number of positions: ", data)
  23.  
  24.     data = int(data)
  25.     positions = []
  26.     for i in range(data):
  27.         data = sock.recv(4)
  28.         data = struct.unpack("!I", data)[0]
  29.         positions.append(data)
  30.     print(positions)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top