Note that there are some explanatory texts on larger screens.

plurals
  1. POSend Raw hex data in jython udp packet
    primarykey
    data
    text
    <p>I'm experience with Java, but I have to integrate a java library into a co-workers python code. Enter jython, yay!</p> <p>We are trying to send a UDP packet with a very specific data section.</p> <p>We are building up the packet like so:</p> <pre><code>version = 0x0001 referenceNumber = 0x2323 bookID = byteArray('df82818293819dbafde818ef') </code></pre> <p>For easy of explanation assume byteArray takes in a string of hex digits and returns a byte array</p> <p>We then build the packet:</p> <pre><code>packet = hex(version) packet += hex(referenceNumber) packet += bookID </code></pre> <p>and send it out the socket.</p> <p>I know this is incorrect, the data types can't be right ,so the concat wont do the right thing. How do we build up this packet properly? The python documentation say that s.sendTo() takes a string? I think I want an alternative to s.sendTo() that takes a byte array.</p> <p>We want the packet to arrive at the server with the udp data section looking like:</p> <pre><code>00 01 23 23 df 82 81 82 93 81 9d ba fd e8 18 ef </code></pre> <p>What is the proper approach to do this in python?</p> <p>We are using wireshark to verify the packet arrives properly and right now the udp data section looks as if python converts each field as an ascii representation. For example, the referenceNumber field comes accross as the ascii values for the literal string '0x2323'. Which makes sense because s.sendTo() takes a string.</p> <p>====================SOLUTION==============================</p> <p>Yup, that does it... shows how new I am to python. For the curious, here is the code:</p> <pre><code>version = '0001' referenceNumber = '2323' packet = a2b_hex(version) packet += a2b_hex(referenceNumber) .. etc </code></pre> <p>then just</p> <pre><code> s.send(packet) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload