Multiple sockets Read and Write.

  • I want to open two sockets and Read data from one socket and write data on the other in accordance with the read data.
    Scenario Read data from socket 1 and write some data on to Socket 2 in parallel and wait for ack from socket 2 and then again write some data on socket 2 and again wait for acknowledgement. During this process socket1 should continue reading data.

    I am new to Qt .Do i need to use Threads. Please let me know how can i proceed

    @Client::Client(QObject* parent): QObject(parent)
    connect(&client, SIGNAL(connected()),
    this, SLOT(startTransfer()));
    connect(&tcpsocket, SIGNAL(connected()),
    this, SLOT(startTransfer1()));

    connect(&client, SIGNAL(readyRead()),
    this, SLOT(readDataFromConnection()));
    connect(&tcpsocket, SIGNAL(readyRead()),
    this, SLOT(read_ackfromTagbc()));

    when i do it in the above way the Qt crashes.

  • If you want to use thread you haven't to use events. You can use functions like ReadyRead, waitforbyteswritten...

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Theses connect statements should not lead to crashes. Where does it happen exactly ?

  • Hello vsnmtej
    I think your program crashed because You did not allocate memory to "&client" and "&tcpsocket" using "new " in constructor.
    Most of the time Crashes happens Whenever you donot allocate memory to the pointer variables using new operator and you use them directly.
    Here in given code ,i can't see the allocation to socket variables.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.