f1.py
#-*-coding:utf-8-*-ImportSocketImportstructImportSQLAlchemyImportPandas########################################################################classSocket:#---------------------------------------------------------------------- def __init__(Self, Host ='192.168.1.3', Port = 12345): Self. Host=Host Self. Port=Port#---------------------------------------------------------------------- defRun_server (self): Socket=Socket.socket (socket.af_inet, socket. SOCK_STREAM) Socket.bind (self. Host, self. Port)) Socket.listen (5) Engine= Sqlalchemy.create_engine ('Mssql+pyodbc://sa:[email protected]') " "Modified 1" "Dataframe= Pandas.read_sql ('SH', Engine) I= List (dataframe['Date'].index) O= dataframe['Open'] H= dataframe[' High'] L= dataframe[' Low'] C= dataframe['Close'] V= dataframe['Volume'] I=0 whiletrue:connection, Address=socket.accept ()ifCONNECTION.RECV (1024x768) = = B'Link' andI <Len (I):" "Modified 2" "connection.send (Struct.pack ('i5f', I[i], o[i], h[i], l[i], c[i], v[i])) I+ = 1Else: Connection.close () socket.close ()#---------------------------------------------------------------------- defRun_client (self, Message = b'Link'): Socket=Socket.socket (socket.af_inet, socket. SOCK_STREAM) Socket.connect (self. Host, self. Port) socket.send (Message)" "Modified 3" "I, O, H, L, C, V= Struct.unpack ('i5f', SOCKET.RECV (1024) [: 24]) socket.close ()returnI, O, H, L, C, V
f2.py
# -*-coding:utf-8-*- Import syssys.path.append ('C:\WinPython-32bit-3.5.1.3\myWorkSpace1') Import = F1. Socket () F1. Run_server ()
f3.py
#-*-coding:utf-8-*-Importf1f1=F1. Socket ()ImportMatplotlib.pylab as Plot fromMatplotlib.financeImportCANDLESTICK_OHLC as Drawk" "Modified 1" " Figure= Plot.figure ('made by Dengchaohai') F1= Figure.add_subplot (3, 4, (1, 7), title ='Index', Xlim = [0, 100]) Plot.grid (True) F2= Figure.add_subplot (1, 4, 4, title ='Trading Price', Ylim = [-6, 6]) Plot.grid (True) F3= Figure.add_subplot (3, 4, (9, one), title ='Volume', Xlim = [0, 100]) Plot.grid (True) Quotes=[]true=True whiletrue:i, O, H, L, C, V=F1. Run_client () Quotes.append ((I, O, H, L, C, V)) Drawk (F1, Quotes, Width= 0.5, Colorup ='g', Colordown ='R') f2.axhline (y=0) F3.bar (I, V, Width= 0.5, color ='C', Edgecolor ='C') Plot.pause (0.1) ifI > 100: TRUE=Falsef1.run_client (b'Disconnect')
Python Socket Programming Seven: The application of multiple windows