-
Notifications
You must be signed in to change notification settings - Fork 5
/
FixIME_SERVER.py
62 lines (43 loc) · 1.99 KB
/
FixIME_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
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
# -*- coding: utf-8 -*-
__author__ = 'Voronin Denis Albertovich'
import Server
import datetime
from SysLog import AddToLog
class FIXi_client_thread(Server.ClientThread):
def run(self):
#self.get_session_info()
while True:
if self.type_input_data() == 'data':
self.get_data()
def get_data(self):
#try:
print(str(datetime.datetime.now()) + self.sess.ip + '---' + ' Reserve main data...<-- ', self.sess.data[5:])
self.sess.sql_ins_data()
print(str(datetime.datetime.now()) + self.sess.ip + '---' + ' Send confirm data... --> ', self.details[0])
self. data_parse()
#except Exception:
#print(str(datetime.datetime.now()) + self.sess.ip + '---' + ' Connection refuse...', self.details[0])
def data_parse(self):
if self.sess.data[0:14] == 'data//new_user':
name = self.sess.data[15:len(self.sess.data) - 2]
self.sess.sql_ins_user(name)
self.channel.send(bytes('user_added', 'utf-8'))
print(str(datetime.datetime.now()) + ' user_added')
class Server_fixi(Server.Server):
host = '192.168.0.156'
port = 1900
def start_server(self):
self.run = True
print(str(datetime.datetime.now()) + ' +++++++++++++++++++++++++++++++++++++++++++++++++++')
print(str(datetime.datetime.now()) + " ++ TCP Server Start, waiting clients...")
print(str(datetime.datetime.now()) + ' ++ Server address: ' + self.host + ' Port: ' + str(self.port))
print(str(datetime.datetime.now()) + ' +++++++++++++++++++++++++++++++++++++++++++++++++++')
try:
while True:
if self.run:
channel, details = self.server_socket.accept()
FIXi_client_thread(channel, details).start()
except Exception:
print('---Server Stopped!----')
servfix = Server_fixi('192.168.0.156', 2000)
servfix.start_server()