title: Sending a Dictionary using Sockets in Python?
body: <p>My problem: Ok, I made a little chat program thing where I am basically using sockets in order to send messages over a network. </p>
  
  <p>It works great, but when I decided to take it a step further, I ran into a problem. </p>
  
  <p>I decided to add some encryption to the strings I was sending over the network, and so I went ahead and wrote the script that did that. </p>
  
  <p>The problem is that apparently you can't just send a dictionary through sockets as you might with a string. </p>
  
  <p>I did some research first, and I found this stuff about Pickles. Unfortunately, I couldn't find out exactly how I could use them to convert strings, aside from having it exporting the dictionary to a file, but I can't do that without changing my program. </p>
  
  <p>Can anyone help explain how I am to do this? I've looked around everywhere but I can't seem to find out how. </p>
  
  <p>I've uploaded what I've got so far here, if that comes of any interest to anybody. </p>
  
  <pre><code>print("\n\t\t Fill out the following fields:")
  HOST = input("\nNet Send Server Public IP: ")
  PORT = int(input("\nNet Send Server Port: "))
  #------------------------------------------------
  #Assessing Validity of Connection
  #------------------------------------------------
  try:
      s = socket(AF_INET,SOCK_STREAM)
      s.connect((HOST,PORT))
      print("Connected to server:",HOST,)
  except IOError:
      print("\n\n\a\t\tUndefined Connection Error Encountered")
      input("Press Enter to exit, then restart the script")
      sys.exit()
  #-------------------------------------------------
  #Now Sending and recieving mesages
  #-------------------------------------------------
  
  
  i = True
  while i is True:
      try:
          User_input = input("\n Enter your message: ")
      Lower_Case_Conversion = User_input.lower()
      #Tdirectory just stores the translated letters
      Tdirectory = []
      # x is zero so that it translates the first letter first, evidently
      x = 0
      COUNTLIMIT = len(Lower_Case_Conversion)
      while x &lt; COUNTLIMIT:
          for letter in Lower_Case_Conversion[x]:
              if letter in TRvalues:
                  Tdirectory += [TRvalues[Lower_Case_Conversion[x]]]
          x = x + 1
  
          message = input('Send: ')
          s.send(message.encode())
          print("\n\t\tAwaiting reply from: ",HOST,)
          reply = s.recv(1024)
          print(HOST,"\n : ",reply)
      except IOError:
          print("\n\t\aIOError Detected, connection most likely lost.")
          input("\n\nPress Enter to exit, then restart the script")
  </code></pre>
  
  <p>Oh, and if your wondering what TRvalues is. It's the dictionary that contains the 'translations' for encrypting simple messages. </p>
  
  <pre><code>try:
      TRvalues = {}
      with open(r"C:\Users\Owatch\Documents\Python\FunStuff\nsed.txt", newline="") as f:
          reader = csv.reader(f, delimiter=" ")
          TRvalues = dict(reader)
  </code></pre>
  
  <p>(The translations are held in a .txt it imports)</p>