a guest Feb 15th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import socket
- #First, we need to add the string 'end' to our arr as the very last element
- arr = ['hello', 'strings', 'that', 'need', 'to', 'be', 'transferred', 'across', 'the', 'network', 'using', 'sockets', 'end']
- #Next, we need to set up the client socket connection
- client_socket = socket.socket()
- client_socket.connect(('127.0.0.1', 8000))
- #Next, we loop over the arr, figure out the length of each string, encode that in binary format and send it across.
- #Subsequently, we do the same for the actual string
- for string in arr:
- len_of_string = len(string.encode('utf-8'))
- len_in_bytes = (len_of_string).to_bytes(2, byteorder='little')
- #Finally, we close the socket
RAW Paste Data