openigtlink / OpenIGTLink

Free, open-source network communication library for image-guided therapy
http://openigtlink.org
BSD 3-Clause "New" or "Revised" License
103 stars 185 forks source link

a image transfer station based on OpenIGTLink server communicate with 3D Slicer #239

Closed Natsu-666 closed 3 years ago

Natsu-666 commented 3 years ago

Hi! I want to build a OpenIGTLink server as a image transfer station,which receives dicom image and send it to 3D slicer.The problem is I can receive and send image succefully according to the variable which receive and send function return, but 3D slicer receive nothing actually when I use two different server for receiving and sending.But it did when using the same server to receive and send. Here is my code.

 if (receiverConnectFlag )
{
        receiverSocket = receiver->WaitForConnection();
        if (receiverSocket.IsNotNull()) 
        {
            IgtHeader::Pointer headerMsg = IgtHeader::New();
            headerMsg->InitPack();
            int rs = receiverSocket->Receive(headerMsg->GetPackPointer(), headerMsg->GetPackSize());
            if (rs == headerMsg->GetPackSize())
            {
                headerMsg->Unpack();
                if (strcmp(headerMsg->GetDeviceType(), "IMAGE") == 0)
                {
                    imgMsg->SetMessageHeader(headerMsg); //imgMsg is global
                    imgMsg->AllocatePack();
                    int r = receiverSocket->Receive(imgMsg->GetPackBodyPointer(),
                                              imgMsg->GetPackBodySize());
                    if (r == imgMsg->GetPackBodySize())
                    {
                        receiverInformation = "Receive image successfully!";
                        std::cerr << receiverInformation.toStdString() << std::endl;
                    }
                    if (senderFlag)
                    {
                        /***********sender server send but 3D slicer receive nothing/***********/
                        senderSocket = sender->WaitForConnection();
                        if (senderSocket.IsNotNull())
                        {
                            int s = senderSocket->Send(imgMsg->GetPackPointer(), imgMsg->GetPackSize());
                            if (s)
                            {
                               senderInformation = "Send image successfully!";
                               std::cerr << senderInformation.toStdString() << std::endl;
                            }
                        }
                        senderSocket->CloseSocket();
                      /*************************************************************/

                      /***********receiver server send and 3D slicer receive successfully/***********/
                      int s = receiverSocket->Send(imgMsg->GetPackPointer(), imgMsg->GetPackSize());
                      if (s)
                      {
                         senderInformation = "Send image successfully!";
                         std::cerr << senderInformation.toStdString() << std::endl;
                      }
                    /*************************************************************/
                    }
                }
            }
            receiverSocket->CloseSocket();
        }
        emit setIgtTimerState(true);
}

I don't know what the problem is.

adamrankin commented 3 years ago

Unfortunately you'll have to debug yourself. There's so many issues that could be the problem that we can't debug it for you.

adamrankin commented 3 years ago

Does Slicer see a connection and doesn't receive any data? Have you tried keeping the Slicer connection open and sending data updates?

tokjun commented 3 years ago

I would check if the two servers configured correctly. To set up two servers on the same machine, you need to assign two different port numbers, and create two separate OpenIGTLink client nodes with those port numbers on Slicer.

Natsu-666 commented 3 years ago

Does Slicer see a connection and doesn't receive any data? Have you tried keeping the Slicer connection open and sending data updates?

Yes,there has two different port clients in Slicer and both of them are keep connection with my servers.