forked from WebisD/http-api-without-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
31 lines (24 loc) · 1.01 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from socket import *
from handler.HandlerRequests import Handler
class Server:
def __init__(self, ip, port):
""" Performs the creation of an object of type Server, in addition
will create a handler that will execute on a thread waiting for requests
:param ip: IP where the server will be allocated
:param port: Port where the server will be allocated
"""
self.ip = ip
self.port = port
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
serverSocket.bind((self.ip, self.port))
serverSocket.listen(1)
self.serverSocket = serverSocket
self.handler = Handler(self)
self.handler.start()
def startServer() -> None:
""" It performs the instantiation of an object of type Server, allocating it in the
local ip and port 8083
"""
serverHttp = Server('localhost', 8083)
print("Server started on " + serverHttp.ip + ":" + str(serverHttp.port))