<div dir="ltr"><div><div>I did not try your example yet but I think the issue is due to your local src.c_str() which is destroyed before the send action is really performed (send is a asynchronous function).<br></div>So you can try something like : <br>
<br>else<br>
{<br>
std::string str(args[1]);<br>
std::size_t size = str.size();<br> const char *s = str.c_str();<br>
comm->Send(&size, 1, /* remoteHandle */ 1, 0);<br>
comm->Send(s, size, /* remoteHandle */ 1, 1);<br>
cout << "Send" << endl;<br>
cout << str << endl;<br>
cout << size << endl;<br>
for (std::size_t i = 0; i < size; ++i)<br>
{<br>
cout << int(str[i]) << endl;<br>
} <br> cout << "server comm->Barrier()" << endl;<br>
comm->Barrier();<br>
}<br>
<br><br></div>Regads,<br></div><div class="gmail_extra"><br clear="all"><div><b>Joachim Pouderoux</b><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font size="1"><i>PhD, R&D Enginee</i>r</font> <br>
<b><font size="1"><a href="http://www.kitware.fr" target="_blank">Kitware SAS</a></font></b><br></blockquote>
</div>
<br><br><div class="gmail_quote">2013/4/25 Henry Lehmann <span dir="ltr"><<a href="mailto:henry.lehmann@informatik.tu-freiberg.de" target="_blank">henry.lehmann@informatik.tu-freiberg.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I am playing around with vtkSocketCommunicator. I want to send integral data types and<br>
wrote a program to get myself into this topic. The source is at the end.<br>
If the program is started without command line arguments, vtkSocketCommunicator<br>
goes into server mode and waits for a connection at port 7777. If it is started<br>
with one command line argument, the string is send to the server who<br>
displays it in the terminal. However, the data is not transmitted correctly.<br>
<br>
Consider this example:<br>
At first start in server mode tp receive data:<br>
$ ./program<br>
Secondly start in client mode and send data:<br>
$ ./program ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
<br>
The output of the programs is as follows:<br>
<br>
Server:<br>
comm->WaitForConnection(7777)<br>
Receive<br>
ABCDEFGH???? MNOPQRSTUVWXYZ<br>
26<br>
65<br>
66<br>
67<br>
68<br>
69<br>
70<br>
71<br>
72<br>
1<br>
0<br>
0<br>
0<br>
77<br>
78<br>
79<br>
80<br>
81<br>
82<br>
83<br>
84<br>
85<br>
86<br>
87<br>
88<br>
89<br>
90<br>
comm->Barrier()<br>
comm->CloseConnection()<br>
<br>
Client:<br>
comm->ConnectTo(localhost, 7777)<br>
Send<br>
ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
26<br>
65<br>
66<br>
67<br>
68<br>
69<br>
70<br>
71<br>
72<br>
73<br>
74<br>
75<br>
76<br>
77<br>
78<br>
79<br>
80<br>
81<br>
82<br>
83<br>
84<br>
85<br>
86<br>
87<br>
88<br>
89<br>
90<br>
comm->Barrier()<br>
comm->CloseConnection()<br>
<br>
As you can see the data is not transmitted correctly and the numbers<br>
73, 74, 75, 76 are replaced by 1, 0, 0, 0.<br>
What am i doing wrong? Am i using this class not as intended?<br>
<br>
Thanks in advance,<br>
Henry.<br>
<br>
Source Code:<br>
<br>
#include <vtkNew.h><br>
#include <vtkSocketCommunicator.h><br>
#include <vtkClientServerStream.h><br>
#include <iostream><br>
#include <string><br>
int main(int argc, char *args[])<br>
{<br>
using namespace std;<br>
<br>
vtkNew<vtkSocketCommunicator> comm;<br>
comm->SetPerformHandshake(1);<br>
if (argc == 1)<br>
{<br>
cout << "comm->WaitForConnection(7777)<u></u>" << endl;<br>
comm->WaitForConnection(7777);<br>
}<br>
else if (argc == 2)<br>
{<br>
cout << "comm->ConnectTo(localhost, 7777)" << endl;<br>
comm->ConnectTo("localhost", 7777);<br>
}<br>
comm->Handshake();<br>
comm->Barrier();<br>
if (comm->GetIsServer())<br>
{<br>
std::size_t size = 0;<br>
comm->Receive(&size, 1, /* remoteHandle */ 1, 0);<br>
std::string str(size, '\n');<br>
comm->Receive(&str[0], size, /* remoteHandle */ 1, 1);<br>
cout << "Receive" << endl;<br>
cout << str << endl;<br>
cout << size << endl;<br>
for (std::size_t i = 0; i < size; ++i)<br>
{<br>
cout << int(str[i]) << endl;<br>
}<br>
}<br>
else<br>
{<br>
std::string str(args[1]);<br>
std::size_t size = str.size();<br>
comm->Send(&size, 1, /* remoteHandle */ 1, 0);<br>
comm->Send(str.c_str(), size, /* remoteHandle */ 1, 1);<br>
cout << "Send" << endl;<br>
cout << str << endl;<br>
cout << size << endl;<br>
for (std::size_t i = 0; i < size; ++i)<br>
{<br>
cout << int(str[i]) << endl;<br>
}<br>
}<br>
cout << "comm->Barrier()" << endl;<br>
comm->Barrier();<br>
cout << "comm->CloseConnection()" << endl;<br>
comm->CloseConnection();<br>
return 0;<br>
}<br>
<br>
______________________________<u></u>_________________<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/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/<u></u>listinfo/vtkusers</a><br>
</blockquote></div><br></div>