#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Python bytes are missing after recv from UDP socket


    Code:
    import socket
    import sys
    import datetime
    import os
    
    try:
        username = "root"
        password = "Apacheah64"
        db_name = "DB_GPS"
        table_name = "Tbl_GPS"
        host = ""
        port = 6903
        buf = 4096
    
    except IndexError:
    
        sys.exit(1)
    
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((host, port))
    
    while 1:
        data = s.recv(buf)
        if not data:
            print("Client has exited!")
            break
        else:
            print("\nReceived message '", data,"'")
    
    # Close socket
    s.close()
    the bytes i m received should be 43 bytes, but what i received from client is

    Received message ' b'\x0f\x00\x00\x00NR09G05164\x00' ' ? only 15 bytes. why?

    Below is Original Bytes 43 bytes

    Code:
    00 00 00 01 00 06 ec 44 76 a6 21 c2 00 00 08 00 45 00
    00 2b 08 43 00 00 34 11 81 2b cb 52 50 db 67 0d 7a 19 24 2d
    1a f7 00 17 83 26 0f 00 00 00 4e 52 30 39 47 30 35 31 36 34
    00
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    I've blundered recently, but I swear your 43 original bytes are 59 bytes long. It is 43 without the zeros. Anyway, I don't know the answer.

    Why do you ignore the ASCII nul bytes when you count 43 instead of 59, yet include them in the received message?

    Received message b'\x0f\x00\x00\x00NR09G05164\x00

    Maybe this will help your diagnosis, www.jsoftware.com
    Code:
       A     NB. the transmitted data, in decimal
    0 0 0 1 0 6 236 68 118 166 33 194 0 0 8 0 69 0 0 43 8 67 0 0 52 17 129 43 203 82 80 219 103 13 122 25 36 45 26 247 0 23 131 38 15 0 0 0 78 82 48 57 71 48 53 49 54 52 0
    
    
       # A    NB. tally of the transmitted data
    59
       
    
       A -. 0    NB. sent data without 0
    1 6 236 68 118 166 33 194 8 69 43 8 67 52 17 129 43 203 82 80 219 103 13 122 25 36 45 26 247 23 131 38 15 78 82 48 57 71 48 53 49 54 52
       
    
       # A -. 0   NB. tally of data without 0
    43
       
    
       A { a.    NB. emacs renders as ASCII
    Dv!EC4┬+RPg
    z│$-─┴&NR09G05164
    
    
       ,. _15 (}. ; {.) A    NB. missing and present received data
    ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    │0 0 0 1 0 6 236 68 118 166 33 194 0 0 8 0 69 0 0 43 8 67 0 0 52 17 129 43 203 82 80 219 103 13 122 25 36 45 26 247 0 23 131 38│
    ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │15 0 0 0 78 82 48 57 71 48 53 49 54 52 0                                                                                      │
    └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo