Results 1 to 20 of 58

Thread: Socket Prog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Ok... I hope this may work by QList<>.
    In my new connection slot I need to try like
    QList<QTcpsocket*,sockets>=new QTcpsocket.
    But after declaring as aQList.we have to set socket descriptor or not required? Then we can try to sendtoall().

    Okay now this may work for data to all the clients.... As mentioned above post if I need to send data for specific client.not suddenly at the same time to respective client who has sent data to server...later also...how this process will happen?

  2. #2
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    As suggested I have used QList<> in server application to address all or send data to all clients. Now, all clients are able to send/read data.but, all clients all getting data twice.Any problem in my write function of Server
    Qt Code:
    1. void Server::on_newconn()
    2. {
    3. QTcpSocket *socket = server->nextPendingConnection();
    4. if((socket->state()==QTcpSocket::ConnectedState))
    5. sockets.append(socket);
    6. connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
    7. }
    8. void Server::write()
    9. {
    10. QString data=this->le->text();
    11. foreach(QTcpSocket* socket,sockets)
    12. {
    13. socket->write(CHAT.toUtf8().constData());
    14. }
    15. qDebug("server is sending msgs to all clients");
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TCPClient::read1()
    2. {
    3.  
    4. QByteArray buffer= socket->readLine();
    5. te->setText(buffer);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. client/server prog using UDP
    By rajeshakula in forum Newbie
    Replies: 1
    Last Post: 12th July 2011, 11:43
  2. Build issues when qextsrialport.h is included in Linux prog
    By pupqt in forum Installation and Deployment
    Replies: 1
    Last Post: 7th April 2011, 15:48
  3. Replies: 2
    Last Post: 11th March 2010, 09:46
  4. can the image be displayed as it is in chips prog..
    By sh123 in forum Qt Programming
    Replies: 11
    Last Post: 7th February 2009, 08:15
  5. Qt Prog skip the file reading block
    By dgg32 in forum Qt Programming
    Replies: 10
    Last Post: 10th December 2008, 18:12

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.