Re: [Paraview] Using MobileSocketPlugin to get metadata

2013-04-22 Thread Pat Marion
Hi Travis,

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.

Here is a python example that connects to paraview and receives the
metadata:


import socket
from struct import pack
from struct import unpack


def connect(host, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
return s


def receiveReadyCommand(s):
data = s.recv(4)
assert unpack('i', data)[0] == 1


def sendCommand(s, command):
data = pack('i', command)
s.send(data)


def receiveMetaData(s):
sendCommand(s, 2)
data = s.recv(8)
length = unpack('Q', data)[0]
return s.recv(length)


def main():

s = connect('localhost', 4)
receiveReadyCommand(s)

print receiveMetaData(s)


if __name__ == '__main__':
main()





On Sat, Apr 20, 2013 at 6:23 AM, Bueter, Travis J. (ST-Student) 
tjb...@mail.mst.edu wrote:

  Hi,

 ** **

 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:

 ** **

 // In the main program //

 command = 2;

 if(-1 == send(socket, command, sizeof(command), 0))

 exit(1);

 ** **

 int size;

 unsigned long long length;

 if((size = Receive(socket, length, sizeof(unsigned long
 long)) = 0)

 exit(1);

 cout  size  endl;

 cout  length  endl;

 ** **

 // Receive function //

 int Receive( cons int sk, void* data, int len)

 {

 char* buffer =
 reinterpret_castchar*(data);

 int total = 0;

 do

 {

 int nRecvd = recv(socket,
 buffered+total, len-total, 0);

 if(nRecvd == 0)

 {

 cout 
 “No Data Received”  endl;

 exit(1);**
 **

 }

 if(nRecvd == -1)

 {

 cout 
 “Error”  endl;

 exit(1);**
 **

 }

 total += nRecvd;

 }while(total  len);

 return total;

 }

 ** **

 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! 

 ** **

 Thanks,

 ** **

 *Travis J. Bueter*

 --

 *Missouri University of Science and Technology - Junior*

 B.S. Computer Engineering/Computer Science

 tjb...@mail.mst.edu

 (573)-238-5843

 ** **

 IT RSS

 Treasurer – MST Robotics Competition Team

 --

 ** **

 ___
 Powered by www.kitware.com

 Visit other Kitware open-source projects at
 http://www.kitware.com/opensource/opensource.html

 Please keep messages on-topic and check the ParaView Wiki at:
 

[Paraview] Using MobileSocketPlugin to get metadata

2013-04-19 Thread Bueter, Travis J. (ST-Student)
Hi,

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:

// In the main program //
command = 2;
if(-1 == send(socket, command, sizeof(command), 0))
exit(1);

int size;
unsigned long long length;
if((size = Receive(socket, length, sizeof(unsigned long long)) 
= 0)
exit(1);
cout  size  endl;
cout  length  endl;

// Receive function //
int Receive( cons int sk, void* data, int len)
{
char* buffer = reinterpret_castchar*(data);
int total = 0;
do
{
int nRecvd = recv(socket, 
buffered+total, len-total, 0);
if(nRecvd == 0)
{
cout  No 
Data Received  endl;
exit(1);
}
if(nRecvd == -1)
{
cout  Error 
 endl;
exit(1);
}
total += nRecvd;
}while(total  len);
return total;
}

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!

Thanks,

Travis J. Bueter
--
Missouri University of Science and Technology - Junior
B.S. Computer Engineering/Computer Science
tjb...@mail.mst.edumailto:tjb...@mail.mst.edu
(573)-238-5843

IT RSS
Treasurer - MST Robotics Competition Team
--

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview