473,467 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sending hex number as is

This question may be ased before, but I couldn't find the answer
searching the archive.

Basically, I just want to send a hex number from one machine to the
next:

for example

msg = "Length is "
n = '\x81'
msg += n
sock.send(msg)

The problem is n's value is not fixed. For example,

msg = "Length is "
n = len(somestring)
msg += n # This won't work of course, since n is int

How do I send this msg + n?

Thanks,
Khoa

Jul 18 '05 #1
4 2361
kn*****@megisto.com wrote:
This question may be ased before, but I couldn't find the answer
searching the archive.

Basically, I just want to send a hex number from one machine to the
next:

for example

msg = "Length is "
n = '\x81'
msg += n
sock.send(msg)

The problem is n's value is not fixed. For example,

msg = "Length is "
n = len(somestring)
msg += n # This won't work of course, since n is int

How do I send this msg + n?

Thanks,
Khoa


Just send the number as a string?
(and parse it to an int again on the other side)

Or investigate the struct and/or pickle modules.

Alternatively, depending on the broader scope of what
you are doing, investigate a proper IPC library such
as Pyro.
--Irmen
Jul 18 '05 #2
On 2005-03-21, kn*****@megisto.com <kn*****@megisto.com> wrote:
msg = "Length is "
n = '\x81'
msg += n
sock.send(msg)

The problem is n's value is not fixed. For example,

msg = "Length is "
n = len(somestring)
msg += n # This won't work of course, since n is int

How do I send this msg + n?


n = 0x81
msg = "Length is " + chr(n)

That only works for "hex numbers" than can be properly encoded
as a character in the default encoding.

See the "struct" module for a more general solution.

--
Grant Edwards grante Yow! There's a lot of BIG
at MONEY in MISERY if you have
visi.com an AGENT!!
Jul 18 '05 #3

<kn*****@megisto.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Basically, I just want to send a hex number from one machine to the
next:


'Hex number' is not completely clear. Do you want to send the number in
binary form or in text form. Text form is much easier and more dependable,
so should be prefered unless you have a good reason for binary. When
sending a text string, you still have a choice between decimal and other
representations. Again, decimal is easier and more dependable, and
therefore prefered, unless the receiving end really demands otherwise.

msg = 'The length is %s' % len(something)

Terry J. Reedy

Jul 18 '05 #4
Op 2005-03-21, kn*****@megisto.com schreef <kn*****@megisto.com>:
This question may be ased before, but I couldn't find the answer
searching the archive.

Basically, I just want to send a hex number from one machine to the
next:
Hex numbers don't exist. You have just numbers. Those numbers can
be represented in different ways, but that doesn't make it a different
(kind of) number.
for example

msg = "Length is "
n = '\x81'
msg += n
sock.send(msg)
You are not sending a number, you are sending a string. What you
seem to want is to represent this number in hexadecimal format
on this machine within a string and send that string to an other
machine.
The problem is n's value is not fixed. For example,

msg = "Length is "
n = len(somestring)
msg += n # This won't work of course, since n is int

How do I send this msg + n?


Use string formatting:

msg = "Length is 0x%x" % n

--
Antoon Pardon
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
1
by: DaleMan | last post by:
I'm looking for some help on how to dial a phone number in my application and send a text message to the portable machine that answers the call (cell phone, Palm, etc..). Anyone know of any sites...
7
by: Lau | last post by:
I need to send 1000 emails from an asp.net website. Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP server. But the large amount of emails results in a timeout. My server...
6
by: Eduardo Rosa | last post by:
Somebody knows how I queue email using .Net? thanks a lot
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
2
by: luchyloo | last post by:
-------------------------------------------------------------------------------- What you have to implement You have a message that can be sent on a port. Before sending the message you have to...
7
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of...
10
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area>...
2
by: lstanikmas | last post by:
Hi, I'm validating a form with this ASP but receiving some blank email responses; does anyone see anything wrong with it?: function isFormVarExcluded(thisForm, strToCheck) { var strExcludeVars...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.