기본 콘텐츠로 건너뛰기

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_struct.size += strlen("123abcdef");

    memcpy(fp, &comm_struct,comm_struct.size+4 );
}

동작

Waiting to receive message from client
size 13 1 123abcdef
sent 256 bytes back to ('192.168.2.113', 50692)
Waiting to receive message from client
size 13 2 123abcdef
sent 256 bytes back to ('192.168.2.113', 50693

댓글

이 블로그의 인기 게시물

DELL의 새게이밍 노트북, Inspiron 15 7000 Gaming, Dual Display 문제

Dell New 게이밍노트북 7567  I7 Notebook http://www.dell.com/kr/p/inspiron-15-7567-laptop/pd?ref=PD_OC 7th Generation Intel® Core™ i7 프로세서 8GB 메모리 1TB 하드 드라이브 + 128GB 솔리드 스테이트 드라이브 NVIDIA® GeForce® GTX 1050 Ti (4GB GDDR5 그래픽 메모리 포함) 상세 사양 리눅스 개발환경이 필요해서 여러대 구매한 노트북입니다. 기본적으로 ubuntu 16.04 가 설치되어 있는데, 필요한 개발환경이 ubuntu 이고 별도의 windows 개발용 PC가 있기 때문에 구매를 결정하게 되었습니다. Slim하지 않지만 I7 HQ CPU와 1050TI spec 이 결정하는데 주요했고, 받은 후에 빌드환경 구축후 8 thread compile을 만끽하던중 치명적인 문제를 Display쪽 문제를 발견하고, Dell express 쪽과 전화통화도 하고 문의 메일도 보내서 지원을 받고(진행)중입니다. 추가 :  시간낭비하지 말라고 중간에 업데이트합니다.  해결되었고, 해결방법은  Windows 을 설치한 후 Fn+F8을 눌러서 모드를 확장모드를 선택합니다. 디스플레이 설정이나 드라이버 재설치 같은 방법으로는 조정이 불가능했습니다. --------------------------------------------------------------------- 요즘 다들 Dual monitor 환경일텐데, Dual Monitor를 복제형태로만 지원을 합니다. 14.04 설치후 업데이트시 375.66 Driver가 설치됩니다. nVidia driver가 설치되었으나, 모니터 인식에 문제가 있어서 해상도 확장설정자체를 할 수 없습니다. 기본 ubuntu라서 driver 문제인가 확인하기 위해서 우분투 64bit 환경 NVIDIA...

우분투에서 성가신 자동 실행 처리

우분투운서비스는 종료된지 예전인데 script에 남아 있어서 항상 실행된다 apt-get 패키지가 제거되어도 etc/xdg/autostart 폴더에서 삭제해야 실행되지 않는다. /etc/xdg/autostart$ ls at-spi-dbus-bus.desktop              gnome-settings-daemon.desktop                print-applet.desktop bluetooth-applet-unity.desktop       gnome-sound-applet.desktop                   pulseaudio-kde.desktop bluetooth-applet.desktop             gnome-user-share.desktop                     pulseaudio.desktop deja-dup-monitor.desktop             gsettings-data-convert.desktop               telepathy-indicator.desktop gdu-notification-daemon.desktop      gwibber.desktop                             ...

llama 계열 gguf 제공되는 경우 가져와서 사용하는 예제

llama 계열의 모델이 친절하게 gguf 형태로 제공되는 경우 어떻게 다운받고 어떻게 ollama에 추가하는지 예전에 gguf 파일을 등록하는 유튜브 강의를 보고 메모해두것을 기반으로 2024년 12월31일 추운 겨울 밤 기억을 백업해 봅니다 수동으로 작성한 것은 지우고 copilot으로 포맷을 정리해서 업데이트합니다. Bllossom/llama-3.2-Korean-Bllossom-3B-gguf-Q4_K_M 한국어 모델 추가하기 시작 : MS Copilot과의 질의응답 중 llama 3.2 기반의 한국어 학습 모델을 발견. 현재 사용 모델 : EEVE-Korean-10.8B (약 7.7 GB) 모델 사용 중. llama 3.2 기반 한국어 모델 소개 : 모델 설명 링크 gguf 파일 다운로드 링크 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B  기반 한국어 모델 소개 : 모델 설명 링크 gguf 파일 다운로드 링크 모델 설정 파일 (Modelfile) : FROM llama-3.2-Korean-Bllossom-3B-gguf-Q4_K_M.gguf PARAMETER temperature 0.6 PARAMETER top_p 0.9 TEMPLATE """<|start_header_id|>system<|end_header_id|> Cutting Knowledge Date : December 2023 {{ if .System }}{{ .System }} {{- end }} {{- if .Tools }} When you receive a tool call response, use the output to format an answer to the orginal user question. You are a helpful assistant with tool calling capabilities. {{- end }} <|eot_id|> {{- range $i , $_ := .Messa...