Results 1 to 18 of 18

Thread: TCP Socket not connecting on Release

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    Sorry, I'm developing Modbus protocol and I have some layers. The layer that I show you is the CModbusTCPMaster, and the socket is delivered to the CModbusTCPTransport:

    I had simplified it because it's a bit large code.

    Qt Code:
    1. void CModbusTCPTransport::setSocket(QTcpSocket* pqSocket)
    2. {
    3. bool bC1 = connect(m_pqTCPSocket,SIGNAL(readyRead()),this,SLOT(readResponse()));
    4. bool bC2 = connect(m_pqTCPSocket,SIGNAL(disconnected()),this,SLOT(disconect()));
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void CModbusTCPTransport::sendRequest(CModbusRequest* request)
    2. {
    3. int iLength = 8;
    4. char* pcRequest = new char[260];
    5. pcRequest[0] = request->getTransaction() >> 8;
    6. pcRequest[1] = request->getTransaction();
    7. pcRequest[2] = request->getProtocol() >> 8;
    8. pcRequest[3] = request->getProtocol();
    9. pcRequest[4] = request->getLength() >> 8;
    10. pcRequest[5] = request->getLength();
    11. pcRequest[6] = request->getUnitID();
    12.  
    13. pcRequest[7] = request->getFunctionCode();
    14.  
    15. m_pqTCPSocket->write(pcRequest,iLength);
    16. //Force the Request to be sent
    17. m_pqTCPSocket->flush();
    18. delete[] pcRequest;
    19. }
    20.  
    21. void CModbusTCPTransport::readResponse()
    22. {
    23. //Read the Modbus Header (8 bytes)
    24. qint64 bytesRead = m_pqTCPSocket->read(m_cbuffer,8);
    25. }
    To copy to clipboard, switch view to plain text mode 
    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    Creating a QObject inside "run()" method of the Thread, shows this error:
    Qt Code:
    1. void myThread::run()
    2. {
    3. ...
    4. QObject ob(this);
    5. }
    To copy to clipboard, switch view to plain text mode 

    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is CModbusTCPMaster(02BCAAB0), parent's thread is QThread(019480E0), current thread is CModbusTCPMaster(02BCAAB0)

    I tryied this because when creating the socket, no parent is passed to it. But trying to use "this" as the socket parents gets me the same error.

    Thanks,
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    I have an idea how to solve this:
    -Create a QTcpSocket dervied class that has a SLOT "sendMessage(char*)"
    -My Thread emits a SIGNAL "readySend(char*)" that is connected to the SLOT of the QTcpSocket derived class on a QueuedConnection.

    The problem is that when calling "pqTcpSocket->write", this is done by myThread.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    The QSocketNotifier messages have disapeared using this behaviour.

    The other problem that the server application is not accepting the connection is still getting me errors, but using a simple Qt server aplication it connects well. So, I really don't understand why the other server application is reaching the connection with "QAbstractSocket::RemoteHostClosedError" error code(note that is a third party app that I don't have the source code).

    And finally, the problem that the server recives a different message ... is still getting me a different message.

    Thanks,
    Òscar Llarch i Galán

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: TCP Socket not connecting on Release

    Quote Originally Posted by ^NyAw^ View Post
    But trying to use "this" as the socket parents gets me the same error
    Because the child and parent objects are created in different threads and this is forbidden. Don't try to pass a parent.

    Quote Originally Posted by ^NyAw^ View Post
    And finally, the problem that the server recives a different message ... is still getting me a different message.
    Are the sender and receiver machines of the same architecture (32/64b big/little endianness)?

    Could you check using a network sniffer whether the content "turns incorrect" on the client or on the server? In other words - what is being transmitted over the network? The data that is being sent or the one that is being received?

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    I'm using the same machine to use client and server apps. A Windows XP OS on a 32 bit machine and Qt 4.3.0.

    Wireshark sniffer is not able to capture packages from/to the same machine, so I open a QFile and write the message(increasing by 48 to convert int to char ona ASCII) into it.

    The data that the client is sending is wrong when using Release but it's okay when running on Debug.

    Thanks,
    Òscar Llarch i Galán

  7. #7
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Wink Re: TCP Socket not connecting on Release

    Ã’scar, I'm sure everybody would like to help, but if you want an accurate answer, you will have to isolate your problem, and post a standalone compilable example that shows the bug.

    Usually differences in behavior between debug and release in networking code are caused by either

    1) Timing problems (i.e., race conditions)
    * the order of packet arrival affects you program's logics

    2) Network packet fragmentation (i.e., partial packet arrival)
    * the size of packets received affects your program's behavior

    3) Compiler bugs
    * _usually_ triggered by complex code, try simplifying

    Generally though I'd try to simplify and simplify your code until you have something that's still broken, but can be posted to this forum for review :-).
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TCP Socket not connecting on Release

    Hi,

    1) Timing problems (i.e., race conditions)
    * the order of packet arrival affects you program's logics
    Really do you thing that I do different things on Debug and on Release?

    2) Network packet fragmentation (i.e., partial packet arrival)
    * the size of packets received affects your program's behavior
    The packet size is as maximum 20 bytes long. Dou you really thing that it is packed on different little packages? But, when Debugging the packages that I recive are ok.

    3) Compiler bugs
    * _usually_ triggered by complex code, try simplifying
    Simply I can't.

    Will try to reproduce the problem.
    Òscar Llarch i Galán

Similar Threads

  1. Socket not connecting
    By ComaWhite in forum Qt Programming
    Replies: 14
    Last Post: 11th March 2008, 02:55
  2. Greenphone mini USB socket problem
    By izico in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 25th September 2007, 11:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.