-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvikram-local-server-1.py
More file actions
71 lines (60 loc) · 2.13 KB
/
vikram-local-server-1.py
File metadata and controls
71 lines (60 loc) · 2.13 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from tkinter import *
#import numpy as np
import socket, threading
import random
import datetime as dt
import threading
import argparse
import sqlite3
from datetime import datetime
from localcentralconnectionprog import *
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--start_over", action="store_true")
return parser.parse_args()
class ClientThread(threading.Thread):
def __init__(self, clientAddress, clientsocket):
threading.Thread.__init__(self)
self.csocket = clientsocket
print("New connection added to local server: ", clientAddress)
def run(self):
print("Connection from local client: ", clientAddress)
while True:
try:
data = self.csocket.recv(1024)
msg = data.decode()
if not msg == '':
print("from local client",msg)
auth_status = send_local_data(msg)
print("Authentication Key:",auth_status) # what is happening here?
self.csocket.send(auth_status.encode('utf-8'))
print("\n")
except UnicodeDecodeError:
print("Error in Decoding the String")
except AttributeError:
print("Attribute Incorrect")
if __name__ == "__main__": # WHY IS THIS?
count = 0
args = get_arguments()
if args.start_over is True:
count = 0
else:
try:
count = np.load("checkpoint.npy")
except:
count = 0
host = "192.168.1.2"
port = 9998
Serv_Socket1=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Serv_Socket1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Serv_Socket1.bind((host, port))
print("Vanakkam Central Server")
print("Local Server started")
print("Waiting for client request..")
local_count = int(count)
while True:
Serv_Socket1.listen(1)
clientsock, clientAddress = Serv_Socket1.accept()
newthread = ClientThread(clientAddress, clientsock)
newthread.start()
clientsock.close()