zoukankan      html  css  js  c++  java
  • Python socket编程之七:多窗口的应用

    f1.py

    # -*- coding: utf-8 -*-
    import socket
    import struct
    import sqlalchemy
    import pandas
    ########################################################################
    class Socket:
        #----------------------------------------------------------------------
        def __init__(self, Host = '192.168.1.3', Port = 12345):
            self.Host = Host
            self.Port = Port
        #----------------------------------------------------------------------
        def Run_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:123456@XiTongDSN')
            '''修改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
            while True:            
                Connection, Address = Socket.accept()
                if Connection.recv(1024) == b'Link' and i < len(I):               
                    '''修改2'''                
                    Connection.send(struct.pack('i5f', I[i], O[i], H[i], L[i], C[i], V[i]))
                    i += 1
                else:
                    Connection.close()
                    Socket.close()
        #----------------------------------------------------------------------
        def Run_client(self, Message = b'Link'):
            Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            Socket.connect((self.Host, self.Port))
            Socket.send(Message)
            '''修改3'''
            I, O, H, L, C, V = struct.unpack('i5f', Socket.recv(1024)[:24])
            Socket.close()
            return I, O, H, L, C, V

    f2.py

    # -*- coding: utf-8 -*-
    import sys
    sys.path.append('C:WinPython-32bit-3.5.1.3myWorkSpace1')
    import f1
    F1 = f1.Socket()
    F1.Run_server()

    f3.py

    # -*- coding: utf-8 -*-
    import f1
    F1 = f1.Socket()
    import matplotlib.pylab as Plot
    from matplotlib.finance import candlestick_ohlc as Drawk
    '''修改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, 11), title = 'Volume', xlim = [0, 100])
    Plot.grid(True)
    Quotes = []
    TRUE = True
    while TRUE:
        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)
        if I > 100:
            TRUE = False
    F1.Run_client(b'disconnect')

    录像8

  • 相关阅读:
    大小写敏感性
    Select的深入应用(1)
    SQL模式匹配
    返回日期和时间范围
    利用枚举管理事务逻辑
    自动记录数据的改变时间
    操作日期和时间
    关于Rational Functional Tester (RFT)的简单介绍
    html布局 左右固定,中间只适应,三种方法实现
    js混合计算字符串字节长度
  • 原文地址:https://www.cnblogs.com/blog-3123958139/p/5554728.html
Copyright © 2011-2022 走看看