码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-06-02 23:40:40      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:

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) == bLink 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 = bLink):
        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(bdisconnect)

技术分享

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

标签:

原文地址:http://www.cnblogs.com/blog-3123958139/p/5554728.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!