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) Index= List (dataframe['Date'].index) Close= dataframe['Close'] Volume= dataframe['Volume'] I=0 whiletrue:connection, Address=socket.accept ()ifCONNECTION.RECV (1024x768) = = B'Link' andI <Len (Close):" "Modified 2" "connection.send (Struct.pack ('iff', Index[i], close[i], volume[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" "Index, Close, Volume= Struct.unpack ('iff', SOCKET.RECV (1024) [: 12]) socket.close ()returnIndex, Close, Volume
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" "Modified 1" "Sub1= Plot.subplot (211) Sub2= Plot.subplot (212) Index=[]close=[]volume= [] whileTrue:index, Close, Volume=F1. Run_client () index.append (index) close.append (Close) volume.append (volume)ifIndex > 10: Sub1.plot (Index[index-10:index-1:1], close[index-10:index-1:1]) Sub2.bar (Index[index-10:index-1:1], volume[index-10:index-1:1]) Plot.pause (0.01)
Set your own variable, capitalize the header text!
Python Socket Programming Five: Updating the time-sharing graph