I am fairly new to using python and servers most of what I know I have learnt from youtube.
1.I am trying to make a persistent connection but am not sure where I am going wrong 2. I also want to be able to send large files using chunked transfers. I attached what I have below so far. Any ideas or recommendations?
import WebServer
def main():
myWebServer = WebServer.WebServer(8080)
myWebServer.start()
myWebServer = WebServer.WebServer(8081)
myWebServer.start()
pass
if __name__ == '__main__':
main()
import threading
from socket import *
import ProcessRequest
class WebServer(threading.Thread):
def __init__(self, serverPort):
threading.Thread.__init__(self)
self.serverPort = serverPort # communicate
def run(self):
serverSocket = socket(AF_INET,SOCK_STREAM) serverSocket.bind(('localhost', self.serverPort))
serverSocket.listen(0)
print('server ready')
while True:
try:
connectionSocket,_ = serverSocket.accept()
except IOError:
print("Server Socket Accept Error")
thread1 = ProcessRequest.ProcessRequest(connectionSocket)
thread1.start()
import threading
import mimetypes
from socket import *
class ProcessRequest (threading.Thread):
def __init__(self, connectionSocket):
threading.Thread.__init__(self)
self.connectionSocket = connectionSocket
def run(self):
#while
print(self.connectionSocket)
try:
request = self.connectionSocket.recv(1024)
except IOError:
print("Server Socket Recv Error")
if request:
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
try:
[Method,Request_URI,HHTP_Version] = request.split(" ",2)
print(Method)
print(Request_URI)
print(HHTP_Version)
except ValueError:
print("Request Parse Error:" + request)
try:
# https://www.ietf.org/rfc/rfc2396.txt
[scheme,hier_part]=Request_URI.split(":",1)
print(scheme)
print(hier_part)
except ValueError:
print("No Scheme")
scheme = None
hier_part = Request_URI
0 Answer(s)