Advertisement
toko214

server page 100

Feb 26th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import socket
  2. import os
  3. x = 0
  4. s = socket.socket()
  5. host = socket.gethostname()
  6. port = 80
  7. s.bind(( host , port))
  8. s.listen(5)
  9. name = "file-name="
  10. iname = "image-name="
  11. while True:
  12.     c, addr = s.accept()     # Establish connection with client.
  13.     print 'Got connection from', addr
  14.     print "Receiving..."
  15.     l=c.recv(1024)
  16.     index=l.index(name)
  17.     index=index+len(name)
  18.     index2=l.index("HTTP")
  19.     file_name=l[index:index2]
  20.     print(file_name)
  21.     f=open('upload/'+"("+str(x)+")"+file_name, 'wb')
  22.     while l:
  23.         l=c.recv(1024)
  24.         f.write(l)
  25.     f.close()
  26.     print "Done Receiving"
  27.     c.send('Thank you for connecting')
  28.     c.close()
  29.     x+=1
  30. print "server is shutting down"
  31. s.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement