Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 692621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:40:11+00:00 2026-05-14T02:40:11+00:00

I am having some trouble dissecting a UDP packet. I am receiving the packets

  • 0

I am having some trouble dissecting a UDP packet. I am receiving the packets and storing the data and sender-address in variables ‘data’ and ‘addr’ with:

data,addr = UDPSock.recvfrom(buf)

This parses the data as a string, that I am now unable to turn into bytes. I know the structure of the datagram packet which is a total of 28 bytes, and that the data I am trying to get out is in bytes 17:28.

I have tried doing this:

  mybytes = data[16:19]
  print struct.unpack('>I', mybytes)
  --> struct.error: unpack str size does not match format

And this:

  response = (0, 0, data[16], data[17], 6)
  bytes = array('B', response[:-1])
  print struct.unpack('>I', bytes)
  --> TypeError: Type not compatible with array type

And this:

  print "\nData byte 17:", str.encode(data[17])
  --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128)

More specifically I want to parse what I think is an unsigned int. And now I am not sure what to try next. I am completely new to sockets and byte-conversions in Python, so any advice would be helpful 🙂

Thanks,
Thomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:40:11+00:00Added an answer on May 14, 2026 at 2:40 am

    An unsigned int32 is 4 bytes long, so you have to feed 4 bytes into struct.unpack.

    Replace

    mybytes = data[16:19]
    

    with

    mybytes = data[16:20]
    

    (right number is the first byte not included, i.e. range(16,19) = [16,17,18]) and you should be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having some trouble looping through some xml data. The xml file is structured
Am having some trouble hooking up instance variables in the visual object editor using
I am having trouble with some Ruby on Rails code. I have a data
I’m having some trouble with understanding how IIS is handling static variables on its
Having some trouble with what should be a very simple scenario. For example purposes,
Hey having some trouble trying to maintain transparency on a png when i create
Basically having some trouble with using Hover to hide or show an item. The
Been having some trouble implementing a single-column index in LaTeX. I've been employing the
Im having some trouble with an oracle database. Every time i try to connect,
I´m having some trouble retrieving a collection of strings in a projection: say that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.