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

  • SEARCH
  • Home
  • 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 7790601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:38:03+00:00 2026-06-01T21:38:03+00:00

I know in order to send data through a UDP socket using python has

  • 0

I know in order to send data through a UDP socket using python has to be in the following format “\x41” = A .

I have a python script udp_send.py and I want to send in a hex value to represent a register value on the server side.

I run my script through linux terminal >>python udp_send.py “\x41” . I read the variable using argv[1] in my python script. I did a len check and it is 3 . It ignore \ and take x, 4 and 1 as 1 byte each whereas I want \x41 to represent 1 byte only.

I was then trying to concatenate data=”\x”+”41″ but it did not work.

“\x” is interpreted as escape by python. I am trying to find a way to pass a hex value into my script and send it via UDP socket?

I have achieved the following so far. Send a hex value defined in python script via UDP socket .

from socket import *
from sys import *

## Set the socket parameters
host = <ip-define-here>
port = <port-define-here>
buf = 1024
addr = (host,port)

## Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

## Send messages
data ='\x41'
#data=argv[1] #commented out
if not data:
    print "No data"
else:
    if(UDPSock.sendto(data,addr)):
        print "Sending message ",data

## Close socket
UDPSock.close()

I used wireshark on server side and saw the hex value 41 appear.

Just to be clear “41”(made of 2 bytes) is not the same as “\x41″(one byte only) in python.

My simple question is, how can I take a character “41” and join it with “\x” to form “\x41” so I can assign it to data variable in my python script so I can send it as hex value 41.

  • 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-06-01T21:38:05+00:00Added an answer on June 1, 2026 at 9:38 pm

    In your code, you can convert your arg to proper format, then you can call it with python udp_send.py 0x41

    arg = sys.argv[1]
    
    # intarg = 65 == 0x41
    intarg = int(arg, 16)
    
    # now convert to byte string '\x41'
    hexstring = struct.pack('B', intarg)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to send data from native program written in C through
I know how to send byte data to a server via the udp protocol.
Anyone know of a way to guarantee plugin startup order? I have a plugin
I am using jQuery.post() to send data to the server, when the server sends
I have the following state machine and I want this: create a new order
I've set up this simple script on my local machine: #!/usr/bin/python import socket from
I want to send the data of a UIImage to the server through a
After user places an order I have to send detailed email message containing order
I never really know what order is the best installation or if it even
If you know the order of a B-tree, how do you figure out the

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.