|
int main |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Start client
Definition at line 16 of file example-comm-client-server-vtk.cxx.
24 strncpy(xname, "server",10); 27 if (argc>1 && argv[1][0]== '-'&& argv[1][1]== 'c') 29 strcpy(xname, "client"); 33 printf( "%s start\n",xname); 39 bool use_ssocket= true; 40 vtkSmartPointer<vtkServerSocket> ssocket; 46 snprintf(command,256, "%s -c &",argv[0]); 51 vtkSmartPointer<vtkSocketController> controller =vtkSmartPointer<vtkSocketController>::New(); 52 vtkSmartPointer<vtkSocketCommunicator> comm =vtkSmartPointer<vtkSocketCommunicator>::New(); 54 controller->SetCommunicator(comm); 55 controller->Initialize(); 67 ssocket=vtkSmartPointer<vtkServerSocket>::New(); 68 rc=ssocket->CreateServer(port); 69 printf( "%s vtkServerSocket::CreateServer: rc=%d\n",xname, rc); 74 while (iwait<nwait && rc==0) 76 printf( "%s wait...\n",xname); 78 rc=comm->WaitForConnection(ssocket,100); 80 rc=comm->WaitForConnection(port); 82 printf( "%s wait: rc=%d\n",xname, rc); 83 std::this_thread::sleep_for (std::chrono::milliseconds(100)); 91 while (iwait<nwait && rc==0) 93 printf( "%s connect to ...\n",xname); 94 rc=comm->ConnectTo( "localhost",port); 95 printf( "%s connect: rc=%d\n",xname, rc); 102 printf( "%s connected \n",xname); 106 printf( "%s give up waiting\n",xname); 110 rc=comm->Handshake(); 111 printf( "%s handshake %d\n",xname,rc); 114 assert(comm->GetIsServer()); 116 assert(!comm->GetIsServer()); 119 int iproc=comm->GetLocalProcessId(); 120 int nproc=comm->GetNumberOfProcesses(); 121 printf( "%s: nproc=%d, iproc=%d\n",xname, nproc,iproc); 133 printf( "%s Barrier\n",xname); 142 rc=comm->Send(&zahl,1,remoteHandle,tag); 143 printf( "%s send %d: %d\n",xname,zahl, rc); 144 std::this_thread::sleep_for (std::chrono::milliseconds(100)); 149 rc=comm->Receive(&zahl,1,remoteHandle,tag); 150 printf( "%s receive %d: %d\n",xname,zahl, rc); 158 rc=comm->Send(&zahl,1,remoteHandle,tag); 159 printf( "%s send %d: %d\n",xname,zahl, rc); 164 rc=comm->Receive(&zahl,1,remoteHandle,tag); 165 printf( "%s receive %d: %d\n",xname,zahl, rc); 169 std::this_thread::sleep_for(std::chrono::milliseconds(20)); 170 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); 178 for ( int j = 0; j < Ny; j++) 179 for ( int i = 0; i < Nx; i++) 181 points->InsertNextPoint(i, j, 100*i+j); 183 rc=comm->Send(points->GetData(),remoteHandle,tag); 184 printf( "%s send %d points: %d\n",xname,static_cast<int>(points->GetNumberOfPoints()), rc); 188 rc=comm->Receive(points->GetData(),remoteHandle,tag); 189 printf( "%s received %d points: %d\n",xname,static_cast<int>(points->GetNumberOfPoints()), rc); 190 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 193 for ( int i=0;i<points->GetNumberOfPoints();i++) 196 points->GetPoint(i,x); 197 printf( "%s: point %03.1f %03.1f %03.1f\n",xname,x[0],x[1],x[2]); 204 rc=comm->GetIsConnected(); 205 printf( "%s connected %d\n",xname,rc); 206 rc=comm->Handshake(); 207 printf( "%s handshake %d\n",xname,rc); 211 printf( "%s Barrier\n",xname); 218 std::this_thread::sleep_for(std::chrono::milliseconds(500)); 219 rc=comm->GetIsConnected(); 220 printf( "%s connected %d\n",xname,rc); 221 rc=comm->Handshake(); 222 printf( "%s handshake %d\n",xname,rc); 224 printf( "%s lost connection\n",xname); 227 comm->CloseConnection(); 228 printf( "%s stop\n",xname);
|