기본 콘텐츠로 건너뛰기

10월, 2016의 게시물 표시

python 에서 Network으로 전송된 Byte 데이타 처리예

Pythonjc서 제공하는 기본적인것만 가지고 간단한 GUI 를 가진 모니터링 프로그램을 구현하려고 하는데 Tk로 해보려고 생각중 인데 Network 으로 전송받은 데이타는 어떻게 unpack 하는지 몰라서 검색을 좀 했는데   string 문자열처럼 format이라는것을 이용해서 Byte를 분리해내다니 Python 참 신기한것 같다. http://stackoverflow.com/questions/15596118/parsing-c-structs-in-python 수신부         data = client.recv(data_payload)         if data:             #             data_size, data_process, data_buf  = unpack('             #print "Data: %s" % data             print "size %d %d %s" % (data_size, data_process, data_buf)             sent_data_size = client.send(data) 송신부 struct _pd_info {     int size;     int count;     char buf[256-8]; }; struct _pd_info comm_struct={0,}; _send_struct(char * fp) {     static int process_num;     process_num++;     memset(&comm_struct, 00, sizeof(struct _pd_info));     comm_struct.count = process_num;     comm_struct.size = 4;     //     memcpy(&comm_struct.buf, "123abcdef", strlen("123abcdef"));     comm

Python GUI + Echo (Recv) Server Simple Sample

GUI 와 echo server (thread)로 동작하는 예제 import tkinter as tk import tkinter.ttk as ttk import threading import echo_server as myserver import datetime def run_echo_server(port=1234):     myserver.echo_server(port)         class workclass(threading.Thread):     def run(self):         run_echo_server()     class Window(ttk.Frame):     def __init__(self, master=None):         super().__init__(master)         hellolabel = ttk.Button(self, text="헬로" )         quitButton =ttk.Button(self, text="Quit", command=self.quit)         hellolabel.pack()         quitButton.pack()         self.pack() if __name__ == '__main__':     th1 = workclass()     th1.setDaemon(True)     th1.start()     window = Window()     window.master.title("Hello")     window.master.mainloop()