Python socket编程之七:多窗口的应用

Posted 佩雷尔曼的信徒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.3\\myWorkSpace1\')
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

以上是关于Python socket编程之七:多窗口的应用的主要内容,如果未能解决你的问题,请参考以下文章

python socket编程

爬坑Python 3.6 在 Socket 编程时出现类型错误 TypeError: a bytes-like object is required, not 'str'(示例代码(代

python编程基础之七

python/socket编程之粘包

彻头彻尾理解JVM系列之七:对象在分代模型中的流转过程是怎样的?

彻头彻尾理解JVM系列之七:对象在分代模型中的流转过程是怎样的?