Now i can explain better than previous messages.<br>This string has to be sent to another host via UDP with the previous attached simple client/server udp implementation in python. <br>The big problem is:<br>The packet <span style="font-weight: bold;">
MUST</span> be like this c struct:
<br><span style="font-family: courier new,monospace;"><br>#define PAYLOAD_LENGHT 5000</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
struct command_hdr {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> int lenght; // sizeof(payload) = sizeof(int) + strlen(payload)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> unsigned char payload[PAYLOAD_LENGHT]; // the xml string</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">} __attribute__ ((packed));
</span><br style="font-family: courier new,monospace;"><br><span style="font-family: arial,sans-serif;">How can i do it in python?</span><br><br><div><span class="gmail_quote">2006/1/24, Sbaush <<a href="mailto:sbaush@gmail.com">
sbaush@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I can specify the question, so you can request me easily...<br>
The int should be an integer of 32 bit fixed. This is total packet size. The string should contain XML.<br>In this example the string is taken from keyboard, so for example.
<br>Thanks all for your helps...<br><br><div><span class="gmail_quote">2006/1/24, Sbaush <<a href="mailto:sbaush@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">sbaush@gmail.com</a>>:
</span><div><span class="e" id="q_108fcd83cf382da0_1"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all, i have a python udp client/server.<br>I would send a packed like this: |int|string| . How can i do it with tih client?<br>Another question: buf is the total packet size?<br>
<pre><span style="color: rgb(255, 0, 255);">from</span> socket <span style="color: rgb(255, 0, 255);">import</span> <span style="color: rgb(255, 0, 255);">*</span>
<span style="color: rgb(128, 128, 128);"><i># Set the socket parameters</i></span>
host <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(221, 0, 0);">"<a href="http://192.168.11.49" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">192.168.11.49</a>"
<br></span>
port <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(0, 0, 255);">21567</span>
buf <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(0, 0, 255);">1024</span>
addr <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(255, 0, 255);">(</span>host,port<span style="color: rgb(255, 0, 255);">)</span>
<span style="color: rgb(128, 128, 128);"><i># Create socket</i></span>
UDPSock <span style="color: rgb(255, 0, 255);">=</span> socket<span style="color: rgb(255, 0, 255);">(</span>AF_INET,SOCK_DGRAM<span style="color: rgb(255, 0, 255);">)</span>
def_msg <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(221, 0, 0);">"===Enter message to send to server==="</span><span style="color: rgb(255, 0, 255);">;</span>
<b>print</b> <span style="color: rgb(221, 0, 0);">"\n"</span>,def_msg<br><br><span style="color: rgb(128, 128, 128);"><i># Send messages</i></span>
<b>while</b> <span style="color: rgb(255, 0, 255);">(</span><span style="color: rgb(0, 0, 255);">1</span><span style="color: rgb(255, 0, 255);">):</span>
data <span style="color: rgb(255, 0, 255);">=</span> <span style="color: rgb(128, 0, 0);">raw_input</span><span style="color: rgb(255, 0, 255);">(</span><span style="color: rgb(221, 0, 0);">'>> '</span><span style="color: rgb(255, 0, 255);">
)</span>
<b>if</b> <b>not</b> data<span style="color: rgb(255, 0, 255);">:</span>
<b>break</b>
<b>else</b><span style="color: rgb(255, 0, 255);">:</span>
<b>if</b><span style="color: rgb(255, 0, 255);">(</span>UDPSock.sendto<span style="color: rgb(255, 0, 255);">(</span>data,addr<span style="color: rgb(255, 0, 255);">)):</span>
<b>print</b> <span style="color: rgb(221, 0, 0);">"Sending message '"</span>,data,<span style="color: rgb(221, 0, 0);">"'.....<done>"</span>
<span style="color: rgb(128, 128, 128);"><i># Close socket</i></span>
UDPSock.close<span style="color: rgb(255, 0, 255);">()</span></pre><br><br clear="all"><br>-- <br><span>Sbaush
</span></blockquote></span></div></div><br><br clear="all"><br>-- <br><span class="sg">Sbaush
</span></blockquote></div><br><br clear="all"><br>-- <br>Sbaush