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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<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">192.168.11.49</a>"</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
<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>Sbaush