<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Thanks for reply again.<br>
      I now use a char buffer of a fixed size and initialize it to
      "ABCD...XYZ".<br>
      I use it for sending and receiving. However the error still
      remains.<br>
      <br>
      Henry<br>
      <br>
      Output:<br>
      Server:<br>
      comm-&gt;WaitForConnection(7777)<br>
      Receive<br>
      Data<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-&gt;CloseConnection()<br>
      <br>
      Client:<br>
      comm-&gt;ConnectTo(localhost, 7777)<br>
      Send<br>
      Data<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-&gt;CloseConnection()<br>
      <br>
      Updated Source Code:<br>
      #include &lt;vtkNew.h&gt;<br>
      #include &lt;vtkSocketCommunicator.h&gt;<br>
      #include &lt;vtkClientServerStream.h&gt;<br>
      #include &lt;iostream&gt;<br>
      #include &lt;string&gt;<br>
      int main(int argc, char *args[])<br>
      {<br>
      &nbsp;&nbsp;&nbsp; using namespace std;<br>
      &nbsp;&nbsp;&nbsp; vtkNew&lt;vtkSocketCommunicator&gt; comm;<br>
      &nbsp;&nbsp;&nbsp; comm-&gt;SetPerformHandshake(1);<br>
      &nbsp;&nbsp;&nbsp; if (argc == 1)<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;WaitForConnection(7777)" &lt;&lt;
      endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;WaitForConnection(7777);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; else if (argc == 2)<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;ConnectTo(localhost, 7777)"
      &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;ConnectTo("localhost", 7777);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; comm-&gt;Handshake();<br>
      &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
      &nbsp;&nbsp;&nbsp; char buffer[1024] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";<br>
      &nbsp;&nbsp;&nbsp; if (comm-&gt;GetIsServer())<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Receive" &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::size_t size;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Receive(&amp;size, 1, /* remoteHandle */ 1, 0);<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Receive(&amp;buffer[0], size, /* remoteHandle */
      1, 1);<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Data" &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; int(buffer[i]) &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; else<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Send" &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::size_t size = strlen(buffer);<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Send(&amp;size, 1, /* remoteHandle */ 1, 0);<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Send(&amp;buffer[0], size, /* remoteHandle */ 1,
      1);<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Data" &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; int(buffer[i]) &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;CloseConnection()" &lt;&lt; endl;<br>
      &nbsp;&nbsp;&nbsp; comm-&gt;CloseConnection();<br>
      &nbsp;&nbsp;&nbsp; return 0;<br>
      }<br>
      <br>
      On 04/25/2013 01:40 PM, Joachim Pouderoux wrote:<br>
    </div>
    <blockquote cite="mid:5634226895877107948@unknownmsgid" type="cite">
      <div>Once again. Do not trust str.c_str(), it is here valid only
        during the call of the function. Try to copy it into a char* and
        send this buffer instead.<br>
        <br>
        Joachim</div>
      <div>
        <br>
        Le 25 avr. 2013 &agrave; 12:49, Henry Lehmann &lt;<a
          moz-do-not-send="true"
          href="mailto:henry.lehmann@informatik.tu-freiberg.de">henry.lehmann@informatik.tu-freiberg.de</a>&gt;
        a &eacute;crit&nbsp;:<br>
        <br>
      </div>
      <blockquote type="cite">
        <div>
          <meta content="text/html; charset=ISO-8859-1"
            http-equiv="Content-Type">
          <div class="moz-cite-prefix">Thanks for your reply.<br>
            <br>
            I changed the program, but the error remains the same.<br>
            I put the Barrier inside the if-else-scopes so the local
            variables will<br>
            not get destroyed until the barrier is reached by all<br>
            processes. <br>
            <br>
            I even put a barrier behind the send of the size, so that<br>
            the size is send/received correctly before the string
            buffers<br>
            for receiving the strings are created.<br>
            <br>
            I changed the example to send the same string 2 times.<br>
            For the second time it works and for the first time<br>
            the wrong data always is at the same position.<br>
            <br>
            Henry<br>
            <br>
            New Output:<br>
            Server:<br>
            comm-&gt;WaitForConnection(7777)<br>
            Receive<br>
            comm-&gt;Barrier()<br>
            comm-&gt;Barrier()<br>
            Data<br>
            65, 65<br>
            66, 66<br>
            67, 67<br>
            68, 68<br>
            69, 69<br>
            70, 70<br>
            71, 71<br>
            72, 72<br>
            1, 73<br>
            0, 74<br>
            0, 75<br>
            0, 76<br>
            77, 77<br>
            78, 78<br>
            79, 79<br>
            80, 80<br>
            81, 81<br>
            82, 82<br>
            83, 83<br>
            84, 84<br>
            85, 85<br>
            86, 86<br>
            87, 87<br>
            88, 88<br>
            89, 89<br>
            90, 90<br>
            comm-&gt;CloseConnection()<br>
            <br>
            Client:<br>
            comm-&gt;ConnectTo(localhost, 7777)<br>
            Send<br>
            comm-&gt;Barrier()<br>
            comm-&gt;Barrier()<br>
            Data<br>
            65, 65<br>
            66, 66<br>
            67, 67<br>
            68, 68<br>
            69, 69<br>
            70, 70<br>
            71, 71<br>
            72, 72<br>
            73, 73<br>
            74, 74<br>
            75, 75<br>
            76, 76<br>
            77, 77<br>
            78, 78<br>
            79, 79<br>
            80, 80<br>
            81, 81<br>
            82, 82<br>
            83, 83<br>
            84, 84<br>
            85, 85<br>
            86, 86<br>
            87, 87<br>
            88, 88<br>
            89, 89<br>
            90, 90<br>
            comm-&gt;CloseConnection()<br>
            <br>
            Updated source code:<br>
            #include &lt;vtkNew.h&gt;<br>
            #include &lt;vtkSocketCommunicator.h&gt;<br>
            #include &lt;vtkClientServerStream.h&gt;<br>
            #include &lt;iostream&gt;<br>
            #include &lt;string&gt;<br>
            int main(int argc, char *args[])<br>
            {<br>
            &nbsp;&nbsp;&nbsp; using namespace std;<br>
            <br>
            &nbsp;&nbsp;&nbsp; vtkNew&lt;vtkSocketCommunicator&gt; comm;<br>
            &nbsp;&nbsp;&nbsp; comm-&gt;SetPerformHandshake(1);<br>
            &nbsp;&nbsp;&nbsp; if (argc == 1)<br>
            &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;WaitForConnection(7777)"
            &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;WaitForConnection(7777);<br>
            &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; else if (argc == 2)<br>
            &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;ConnectTo(localhost, 7777)"
            &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;ConnectTo("localhost", 7777);<br>
            &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; comm-&gt;Handshake();<br>
            &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
            &nbsp;&nbsp;&nbsp; if (comm-&gt;GetIsServer())<br>
            &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Receive" &lt;&lt; endl;<br>
            <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::size_t size = 0;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Receive(&amp;size, 1, /* remoteHandle */ 1,
            0);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;Barrier()" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
            <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::string str1(size, '\n');<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::string str2(size, '\n');<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Receive(&amp;str1[0], size, /* remoteHandle
            */ 1, 1);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Receive(&amp;str2[0], size, /* remoteHandle
            */ 1, 2);<br>
            <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;Barrier()" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Data" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; int(str1[i]) &lt;&lt; ", "
            &lt;&lt; int(str2[i]) &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; else<br>
            &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Send" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::string str1(args[1]);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::string str2(args[1]);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::size_t size = str1.size();<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Send(&amp;size, 1, /* remoteHandle */ 1,
            0);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;Barrier()" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
            <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Send(str1.c_str(), size, /* remoteHandle */
            1, 1);<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Send(str2.c_str(), size, /* remoteHandle */
            1, 2);<br>
            <br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;Barrier()" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Data" &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; int(str1[i]) &lt;&lt; ", "
            &lt;&lt; int(str2[i]) &lt;&lt; endl;<br>
            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; }<br>
            &nbsp;&nbsp;&nbsp; cout &lt;&lt; "comm-&gt;CloseConnection()" &lt;&lt;
            endl;<br>
            &nbsp;&nbsp;&nbsp; comm-&gt;CloseConnection();<br>
            &nbsp;&nbsp;&nbsp; return 0;<br>
            }<br>
            <br>
            <br>
            The new source code is:<br>
            <br>
            On 04/25/2013 12:20 PM, Joachim Pouderoux wrote:<br>
          </div>
          <blockquote
cite="mid:CACJ=gTiJ3DEvZiYFSz=eyGYiqRsXmKN6kXn0KAXJmZPAQA=M5A@mail.gmail.com"
            type="cite">
            <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>
                &nbsp; &nbsp; {<br>
                &nbsp; &nbsp; &nbsp; &nbsp; std::string str(args[1]);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; std::size_t size = str.size();<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char *s = str.c_str();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Send(&amp;size, 1, /* remoteHandle */
                1, 0);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Send(s, size, /* remoteHandle */ 1, 1);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; "Send" &lt;&lt; endl;<br>
                &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; str &lt;&lt; endl;<br>
                &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; size &lt;&lt; endl;<br>
                &nbsp; &nbsp; &nbsp; &nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
                &nbsp; &nbsp; &nbsp; &nbsp; {<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; int(str[i]) &lt;&lt; endl;<br>
                &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; <br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "server comm-&gt;Barrier()"
                &lt;&lt; endl;<br>
                &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comm-&gt;Barrier();<br>
                &nbsp; &nbsp; }<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&amp;D Enginee</i>r</font> <br>
                  <b><font size="1"><a moz-do-not-send="true"
                        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">&lt;<a moz-do-not-send="true"
                    href="mailto:henry.lehmann@informatik.tu-freiberg.de"
                    target="_blank">henry.lehmann@informatik.tu-freiberg.de</a>&gt;</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-&gt;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-&gt;Barrier()<br>
                  comm-&gt;CloseConnection()<br>
                  <br>
                  Client:<br>
                  comm-&gt;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-&gt;Barrier()<br>
                  comm-&gt;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 &lt;vtkNew.h&gt;<br>
                  #include &lt;vtkSocketCommunicator.h&gt;<br>
                  #include &lt;vtkClientServerStream.h&gt;<br>
                  #include &lt;iostream&gt;<br>
                  #include &lt;string&gt;<br>
                  int main(int argc, char *args[])<br>
                  {<br>
                  &nbsp; &nbsp; using namespace std;<br>
                  <br>
                  &nbsp; &nbsp; vtkNew&lt;vtkSocketCommunicator&gt; comm;<br>
                  &nbsp; &nbsp; comm-&gt;SetPerformHandshake(1);<br>
                  &nbsp; &nbsp; if (argc == 1)<br>
                  &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt;
                  "comm-&gt;WaitForConnection(7777)" &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;WaitForConnection(7777);<br>
                  &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; else if (argc == 2)<br>
                  &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; "comm-&gt;ConnectTo(localhost,
                  7777)" &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;ConnectTo("localhost", 7777);<br>
                  &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; comm-&gt;Handshake();<br>
                  &nbsp; &nbsp; comm-&gt;Barrier();<br>
                  &nbsp; &nbsp; if (comm-&gt;GetIsServer())<br>
                  &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; std::size_t size = 0;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Receive(&amp;size, 1, /* remoteHandle
                  */ 1, 0);<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; std::string str(size, '\n');<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Receive(&amp;str[0], size, /*
                  remoteHandle */ 1, 1);<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; "Receive" &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; str &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; size &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; int(str[i]) &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; else<br>
                  &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; std::string str(args[1]);<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; std::size_t size = str.size();<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Send(&amp;size, 1, /* remoteHandle */
                  1, 0);<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; comm-&gt;Send(str.c_str(), size, /*
                  remoteHandle */ 1, 1);<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; "Send" &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; str &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; size &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; for (std::size_t i = 0; i &lt; size; ++i)<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; {<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; int(str[i]) &lt;&lt; endl;<br>
                  &nbsp; &nbsp; &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; }<br>
                  &nbsp; &nbsp; cout &lt;&lt; "comm-&gt;Barrier()" &lt;&lt; endl;<br>
                  &nbsp; &nbsp; comm-&gt;Barrier();<br>
                  &nbsp; &nbsp; cout &lt;&lt; "comm-&gt;CloseConnection()"
                  &lt;&lt; endl;<br>
                  &nbsp; &nbsp; comm-&gt;CloseConnection();<br>
                  &nbsp; &nbsp; return 0;<br>
                  }<br>
                  <br>
                  _______________________________________________<br>
                  Powered by <a moz-do-not-send="true"
                    href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
                  <br>
                  Visit other Kitware open-source projects at <a
                    moz-do-not-send="true"
                    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 VTK FAQ
                  at: <a moz-do-not-send="true"
                    href="http://www.vtk.org/Wiki/VTK_FAQ"
                    target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
                  <br>
                  Follow this link to subscribe/unsubscribe:<br>
                  <a moz-do-not-send="true"
                    href="http://www.vtk.org/mailman/listinfo/vtkusers"
                    target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
                </blockquote>
              </div>
              <br>
            </div>
          </blockquote>
          <br>
        </div>
      </blockquote>
    </blockquote>
    <br>
  </body>
</html>