<div dir="ltr"><div><div>Hi Travis,<br><br></div>I think you mean the MobileRemoteControl plugin, right? Can you paste more of your code? From what you have shared, it's hard to know where things are going wrong. My guess is that you are forgetting to receive the "ready" command: after connecting to the socket, you should first receive 4 bytes and convert them to an int. The int should have the value 1. That's the "ready" command. Next comes the code you showed in your email: send the "send metadata command" which is an int with value 2 and should be 4 bytes. In the code you pasted, you are using sizeof(command) but don't show where you declare command, so that might also be a problem, if your data type is not 4 bytes.<br>
<br></div><div>Here is a python example that connects to paraview and receives the metadata:<br><br><br>import socket<br>from struct import pack<br>from struct import unpack<br><br><br>def connect(host, port):<br> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br>
s.connect((host, port))<br> return s<br><br><br>def receiveReadyCommand(s):<br> data = s.recv(4)<br> assert unpack('i', data)[0] == 1<br><br><br>def sendCommand(s, command):<br> data = pack('i', command)<br>
s.send(data)<br><br><br>def receiveMetaData(s):<br> sendCommand(s, 2)<br> data = s.recv(8)<br> length = unpack('Q', data)[0]<br> return s.recv(length)<br><br><br>def main():<br><br> s = connect('localhost', 40000)<br>
receiveReadyCommand(s)<br><br> print receiveMetaData(s)<br><br><br>if __name__ == '__main__':<br> main()<br><br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 20, 2013 at 6:23 AM, Bueter, Travis J. (S&T-Student) <span dir="ltr"><<a href="mailto:tjbxv7@mail.mst.edu" target="_blank">tjbxv7@mail.mst.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am trying to get the “metadata” from ParaView by connecting to the socket. I’m having an issue where I am correctly sending the command to send the data but I’m not receiving the length value or string correctly. Below is my method how
I am currently trying to get the length value:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">// In the main program //<u></u><u></u></p>
<p class="MsoNormal"> command = 2;<u></u><u></u></p>
<p class="MsoNormal"> if(-1 == send(socket, &command, sizeof(command), 0))<u></u><u></u></p>
<p class="MsoNormal"> exit(1);<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> int size;<u></u><u></u></p>
<p class="MsoNormal"> unsigned long long length;<u></u><u></u></p>
<p class="MsoNormal"> if((size = Receive(socket, &length, sizeof(unsigned long long)) <= 0)<u></u><u></u></p>
<p class="MsoNormal"> exit(1);<u></u><u></u></p>
<p class="MsoNormal"> cout << size << endl;<u></u><u></u></p>
<p class="MsoNormal"> cout << length << endl;<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">// Receive function //<u></u><u></u></p>
<p class="MsoNormal" style="text-indent:.5in">int Receive( cons int sk, void* data, int len)<u></u><u></u></p>
<p class="MsoNormal" style="text-indent:.5in">{<u></u><u></u></p>
<p class="MsoNormal"> char* buffer = reinterpret_cast<char*>(data);<u></u><u></u></p>
<p class="MsoNormal"> int total = 0;<u></u><u></u></p>
<p class="MsoNormal"> do<u></u><u></u></p>
<p class="MsoNormal"> {<u></u><u></u></p>
<p class="MsoNormal"> int nRecvd = recv(socket, buffered+total, len-total, 0);<u></u><u></u></p>
<p class="MsoNormal"> if(nRecvd == 0)<u></u><u></u></p>
<p class="MsoNormal"> {<u></u><u></u></p>
<p class="MsoNormal"> cout << “No Data Received” << endl;<u></u><u></u></p>
<p class="MsoNormal"> exit(1);<u></u><u></u></p>
<p class="MsoNormal"> }<u></u><u></u></p>
<p class="MsoNormal"> if(nRecvd == -1)<u></u><u></u></p>
<p class="MsoNormal"> {<u></u><u></u></p>
<p class="MsoNormal"> cout << “Error” << endl;<u></u><u></u></p>
<p class="MsoNormal"> exit(1);<u></u><u></u></p>
<p class="MsoNormal"> }<u></u><u></u></p>
<p class="MsoNormal"> total += nRecvd;<u></u><u></u></p>
<p class="MsoNormal"> }while(total < len);<u></u><u></u></p>
<p class="MsoNormal"> return total;<u></u><u></u></p>
<p class="MsoNormal"> }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Now in the source code of the MobileSocketPlugin, I added a printf to show the value of “length” before it is sent over the socket. When I run my code, it succeeds without an error but the value of my “length” is not equal. For example,
if I connect and run my code immediately after starting up ParaView, it always sends a value of “1733” but I receive a value of “7443178323969” every time. I’m really not sure what I need to change to get this correct. If someone could point me in the right
direction on what I need to be doing to receive the metadata through MobileSocketPlugin, I would greatly appreciate it!
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b><span style="font-family:"Times New Roman","serif"">Travis J. Bueter<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif"">----------------------------------------------------------------------<u></u><u></u></span></p>
<p class="MsoNormal"><i><span style="font-family:"Times New Roman","serif"">Missouri University of Science and Technology - Junior<b><u></u><u></u></b></span></i></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif"">B.S. Computer Engineering/Computer Science<u></u><u></u></span></p>
<p class="MsoNormal"><a href="mailto:tjbxv7@mail.mst.edu" target="_blank"><span style="font-family:"Times New Roman","serif";color:blue">tjbxv7@mail.mst.edu</span></a><span style="font-family:"Times New Roman","serif""><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif""><a href="tel:%28573%29-238-5843" value="+15732385843" target="_blank">(573)-238-5843</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif"">IT RSS<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif"">Treasurer – MS&T Robotics Competition Team<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif"">----------------------------------------------------------------------<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" target="_blank">http://paraview.org/Wiki/ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.paraview.org/mailman/listinfo/paraview" target="_blank">http://www.paraview.org/mailman/listinfo/paraview</a><br>
<br></blockquote></div><br></div></div>