title: chat server raises TypeError: descriptor 'encode' requires a 'str' object but received a 'unicode'
body: <p>I am pretty much a beginner to Python Socket programming. I made a chat server, but it doesn't work right.</p>
  
  <p>It works fine with receiving data, but does not work with sending data. When i use the 'conn.send()', the client never receives the message. Please help me.</p>
  
  <pre><code>This is my code for the socket server:
  
  '''
      Simple socket server using threads
  '''
  
  import socket
  import sys
  from _thread import *
  
  HOST = ''   # Symbolic name meaning all available interfaces
  PORT = 8888 # Arbitrary non-privileged port
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  print ( 'Socket created on Port: '+str(PORT))
  
  #Bind socket to local host and port
  try:
      s.bind((HOST, PORT))
  except socket.error as msg:
      print ( 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
      sys.exit()
  
  print ( 'Socket bind complete')
  
  #Start listening on socket
  s.listen(10)
  print ( 'Socket now listening')
  
  connectmsg = 'Welcome to OmniBean\'s Chat server!'
  #Function for handling connections. This will be used to create threads
  def clientthread(conn):
      #Sending message to connected client
      print('Sending Welcome Message...')
      #print(conn)
      conn.send(str.encode(connectmsg)) #send only takes string ENCODED!
  
      #infinite loop so that function do not terminate and thread do not end.
      while True:
  
          #Receiving from client
          data = bytes.decode(conn.recv(1024))
          print (data)
          reply = 'OK...' + data
          if not data:
              break
  
          conn.sendall(str.encode(reply))
  
      #came out of loop
      conn.close()
  
  #now keep talking with the client
  while 1:
      #wait to accept a connection - blocking call
      conn, addr = s.accept()
      print ( 'Connected with ' + addr[0] + ':' + str(addr[1]))
      conn.send(str.encode(connectmsg)) 
      #start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
      start_new_thread(clientthread ,(conn,))
  
  s.close()
  </code></pre>
  
  <p>If you can figure out why this is, then can you let me know? My client code is here:
  My client is using the <a href="http://omnibean.github.io/SimpleNet/" rel="nofollow">SimpleNet Library</a> from <a href="http://www.omnibean.96.lt" rel="nofollow">OmniBean</a></p>
  
  <pre><code>import os
  from simplenet import *
  myname = input ('Enter a login name: ')
  host = input('Enter Host Name: ')
  port = input('Enter Host Port: ')
  connect(host,port)
  welcome = receive()
  input('Received Message: '+welcome)
  while True:
      os.system('cls')
      #room = receive()
      #print (room)
      msg = input('Enter a message to send to server: ')
      send(myname+': '+msg)
  </code></pre>
  
  <p>Theoretically, since I send the data twice from the server, the client should receive the data; however, the client just keeps waiting forever for a message from the server that never comes. Please aid me in solving this problem.</p>