title: Simple proxy server "Connection reset by peer" error
body: <p>I am trying to write my own very basic proxy server, I just want my code to send the request and receive a response and sends it back to the browser.
  My code (which I got from <a href="https://null-byte.wonderhowto.com/how-to/sploit-make-proxy-server-python-0161232/" rel="nofollow noreferrer">this</a> tutorial) is: </p>
  
  <pre><code>import socket, sys 
  from thread import * 
  
  try:
      listeningPort = int(raw_input("[*] : inter port to listen to "))
      print "your port is " + str(listeningPort)
  
  except KeyboardInterrupt :
      print "\n[*] : User Requested Interrupt ! "
      print "[*] : Bye :D ! "
      sys.exit();
  
  
  maxConnections = 5
  bufferSize = 4096
  
  
  def start():
      try:
          s = socket.socket(socket.AF_INET , socket.SOCK_STREAM) # init socket
          s.bind(('' , listeningPort)) # binf with listening port 
          s.listen(maxConnections)
          print("[*] : Initializing sockets .. Done")
          print("[*] : listening on port [%d] \n" , listeningPort)
  except Exception , e:
      print("[*] : Unable to initialize socket" + str(e))
      sys.exit(2)
  
  while 1:
      try :
          print "accepting connection"
          conn , addr = s.accept() # accpet connection from browser
          data = conn.recv(bufferSize) # get client data
          start_new_thread(conn_string , (conn , data ,addr)) # start a new thread 
  
      except KeyboardInterrupt:
          s.close()
          print "\nWer'e shutting Down ! "
          print "Bye ! "
          sys.exit(1)
  
  s.close()
  
  def conn_string(conn , data , addr):
      # accepts data from the browser 
      print "herererer"
      try:
          firstLine = data.split('\n')[0]
          url = firstLine.split(' ')[1]
          print "first line " + str(firstLine)
          print "url iss : " + str(url)
          httpPos = url.find("://")
  
      if httpPos == -1:
          temp = url
      else:
          temp = url[(httpPos + 3):]
  
  
      portPoss = temp.find(":") # position of the port 
      webServerPos = temp.find("/") # end of the web server 
  
      if webServerPos == -1:
          webServerPos = len(temp)
  
      webServer = ""
      port = -1
  
      if (portPoss == -1 or webServerPos &lt; portPoss):
          port = 80
          webServer = temp[:webServerPos]
      else: 
          #sepecific port 
          port = int((temp[(portPoss + 1):])[:webServerPos - portPoss - 1])
          webServer = temp[:portPoss]
  
      proxy_server(webServer , port , conn , addr , data)
  
  except Exception , e :
      print "expectionnn " + str(e)
  
  
  
  def proxy_server(webServer , port , conn , addr , data):
      try:
          s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
          # print "here1"
          s.connect((webServer , port))
          # print "here2"
          s.send(data)
          # print "here3"
  
      while 1:
          #Read reply or data from end web server
          #print "here4"
          reply = s.recv(bufferSize)
  
          print "reply count isss" + str(len(reply))
          if (len(reply) &gt; 0):
              conn.send(reply)
              #Send notificaiton to prexy server [US]
              dar = float(len(reply))
              dar = float(dat / 1024)
              dar = "%.3s" % (str(dar))
              dar = "%s KB" % (dar)
              print "[*] Request Done : %s =&gt; %s &lt;= " % (str(addr[0]) , str(dar))
  
          else:
              #break connection if receiving data failed
              break
  
      s.close()
      conn.close()
  
  except socket.error , (value , message):
      print "proxy_server expection " 
      print "value " + str(value)
      print "message : " + str(message)
      s.close()
      conn.close()
      sys.exit(1)
  
  
  
  
  start()
  </code></pre>
  
  <p>It's a very basic proxy server.
  I keep getting and error that the connection was reset by peer (error number 54) , is it because the servers detected that its a home made proxy server and closing the connection? if it is, can you refer me to a more advanced stuff.</p>