Hi all,
I'm trying to bind the ZeroMQ properties with the VTK visualisations
possibility.
Server/client are written in C++ language.
I'm using ZeroMQ 4.0.7 and VTK 6.2.0.
The goal of the server is to receive a greet message from the server and to
respond with the vtkRenderWindow.
The goal of the client is to send an "Hello" message to the server and to
receive a vtkRenderWindow in order to reproduce it.
After the execution I obtain this output with the command "hwclient &
hwserver":
[S] Open connection
[C] Connecting to server…
[C] Sending Hello
[S] Received Hello
terminate called after throwing an instance of 'zmq::error_t'
what(): Bad address
I'm looking forward to hear you.
Thanks,
Paolo Grossi.
//
// Client in C++
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects Cone figure back
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#include "vtkRenderWindow.h"
int main ()
{
// Prepare our context and socket.
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);
// Set the connection.
std::cout << "Connecting to server…" << std::endl;
socket.connect("tcp://localhost:5555");
// Send the greet.
zmq::message_t request(5);
memcpy((void *)request.data(), "Hello", 5);
std::cout << "Sending Hello" << std::endl;
socket.send(request);
// Get the reply.
vtkRenderWindow* renWin = vtkRenderWindow::New();
socket.recv((zmq::message_t *)renWin);
std::cout << "Received Cone" << std::endl;
int i;
for(i = 0; i < 10; ++i) {
// Render the image...
renWin->Render();
}
renWin->Delete();
return 0;
}
//
// Server in C++
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with Cone figure
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
int main () {
// Prepare our context and socket
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
std::cout << "Open connection" << std::endl;
// Wait for next request from client
zmq::message_t request;
socket.recv(&request);
std::cout << "Received Hello" << std::endl;
// Do some 'work'
sleep(1);
// Prepare Cone environment
vtkConeSource *cone = vtkConeSource::New();
cone->SetHeight( 3.0 );
cone->SetRadius( 1.0 );
cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInputConnection( cone->GetOutputPort() );
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper( coneMapper );
vtkRenderer *ren1 = vtkRenderer::New();
ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 );
// Send reply back to client
zmq::message_t reply;
memcpy((void *)reply.data(), renWin, 99999);
socket.send(reply);
cone->Delete();
coneMapper->Delete();
coneActor->Delete();
ren1->Delete();
renWin->Delete();
return 0;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev