Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting string to bytes and send() it
    text
    copied!<p>I'm making a packet sender.</p> <p>Where the user can input the packet they want to send on a RichTextBox.</p> <pre><code>this-&gt;packetdata = (gcnew System::Windows::Forms::RichTextBox()); </code></pre> <p>Sample input:</p> <pre><code>03 00 00 13 0e e0 00 00 00 00 00 01 00 08 00 00 00 00 00 03 00 00 6a 02 f0 80 7f 65 82 00 5e 04 01 01 04 01 01 01 01 ff </code></pre> <p>The server should receive:</p> <pre><code>03 00 00 13 0e e0 00 00 00 00 00 01 00 08 00 00 00 00 00 03 00 00 6a 02 f0 80 7f 65 82 00 5e 04 01 01 04 01 01 01 01 ff </code></pre> <p>But the server is receiving this instead:</p> <pre><code>30 33 20 30 30 20 30 30 20 31 33 20 30 65 20 65 03 00 00 13 0e e 30 20 30 30 20 30 30 20 30 30 20 30 30 20 30 30 0 00 00 00 00 00 20 30 31 20 30 30 20 30 38 20 30 30 20 30 30 20 01 00 08 00 00 30 30 20 30 30 20 30 30 20 30 33 0a 30 30 20 30 00 00 00 03.00 0 30 20 36 61 20 30 32 20 66 30 20 38 30 20 37 66 0 6a 02 f0 80 7f 20 36 35 20 38 32 20 30 30 20 35 65 20 30 34 20 65 82 00 5e 04 30 31 20 30 31 20 30 34 20 30 31 20 30 31 20 30 01 01 04 01 01 0 31 20 30 31 20 66 66 20 1 01 ff </code></pre> <p>How do I convert the data on the <code>RichTextBox</code> to remove all space and treat each as byte and send it.</p> <p>This kind of approach works though:</p> <pre><code>char this[] = {0x03, 0x00, 0x00, 0x13, 0x0e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 0x00, 0x00, 0x6a, 0x02, 0xf0, 0x80, 0x7f, 0x65, 0x82, 0x00, 0x5e, 0x04, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0xff} </code></pre> <p>With that code, the server receives the correct data.</p> <p>So how do I turn the Text inside the TextBox into something like that?</p> <hr> <p>This works</p> <pre><code>int mysendfunc(char *sendbuf, int size); (...) std::string inputpkt = marshal_as&lt;std::string&gt;(this-&gt;packetdata-&gt;Text); std::istringstream reader(inputpkt); std::vector&lt;char&gt; pkt; do { // read as many numbers as possible. for (int number; reader &gt;&gt; std::hex &gt;&gt; number;) { pkt.push_back(number); } // consume and discard token from stream. if (reader.fail()) { reader.clear(); std::string token; reader &gt;&gt; token; } } while (!reader.eof()); int hehe = mysendfunc(pkt.data(), pkt.size()); </code></pre>
 

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