Page 1 of 3 123 LastLast
Results 1 to 20 of 58

Thread: Socket Prog

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

    Default Socket Prog

    Dear All,

    I have developed a SERVER_CLIENT Application, Where Server will receives data from client and present it on the Server Application. I have done with the 1-server and 1-client. If i want to increase the Client Nos. I'm not able to do it.. When same Client application in compiled second time as second client. The data at server end is not processed or to be clear. Data was not sent from Secone client only. How this can be addressed,
    1.either we need to create mulitple sockets.. how this can be done having one-Serverapplication.
    2. or Can we create a Server Application where it can accept mutilple "ports" (e.g server->listen(QHostAddress::Any,1234, server->listen(QHostAddress::Any,1235)) connections ? in the server application while checking for Newconnections.

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    One approach you could try is every time you get an incoming connection from the server you set a socket and the streams for that user, ( you can make a class user to handle all this ).
    So now when a client connects an instance of the class will be created specifically to that user handling his requests.
    You will still have one Server socket to listen and you create a client-socket for every user.
    That's a general approach. You can find several other ways to solve the issue.

    Good Luck.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Quote Originally Posted by Vivek1982 View Post
    1.either we need to create mulitple sockets.. how this can be done having one-Serverapplication.
    This is done automatically. Each incoming connection gets its own QTcpSocket instance.

    Quote Originally Posted by Vivek1982 View Post
    2. or Can we create a Server Application where it can accept mutilple "ports" (e.g server->listen(QHostAddress::Any,1234, server->listen(QHostAddress::Any,1235)) connections ? in the server application while checking for Newconnections.
    No need for multiple listening ports. All connections to a QTcpServer result in new QTcpSocket objects being created, one for each incoming connection/client.

    Cheers,
    _

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

    Default Re: Socket Prog

    Thanks for all your replies. I will give an attempt to create a multiple Sockets for adding new clients into my server application. I hope I may example(Qt inbuilt) for this to unsderstand, how coding/ creating multiple socket can be done.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Just to be sure you understood this correctly: you don't need to create multiple sockets, they are created for you. This is what the QTcpServer ultimately does.

    Cheers,
    _

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

    Default Re: Socket Prog

    Hi. I have tried upto my level how to create a Server to handle many clients, but my non of the debug msgs are working. Im presenting my simple Server client code.plz support me.

    Teamstatus.h
    Qt Code:
    1. class TeamStatus : public QMainWindow {
    2. Q_OBJECT
    3. public:
    4. TeamStatus(QWidget *parent = 0);
    5. ~TeamStatus();
    6. void listen();
    7. void socketdisc();
    8. protected:
    9. void changeEvent(QEvent *e);
    10. void incomingConnection(int socketfd);
    11.  
    12. private:
    13. Ui::TeamStatus *ui1;
    14. QTcpServer *server;
    15. QSet <QTcpSocket*> sockets;
    16. public slots:
    17. void read_socket();
    To copy to clipboard, switch view to plain text mode 

    Teamstatus.cpp
    Qt Code:
    1. TeamStatus::TeamStatus(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui1(new Ui::TeamStatus)
    4. {
    5. ui1->setupUi(this);
    6. server=new QTcpServer(this);
    7. TeamStatus::~TeamStatus()
    8. {
    9.  
    10. delete ui1;
    11. }
    12. void TeamStatus::listen()
    13.  
    14.  
    15. {
    16. QHostAddress hAddr;
    17. hAddr.setAddress("192.168.64.55");
    18.  
    19. server->listen(QHostAddress::Any,1234);
    20. qDebug("Listening to new connection");
    21. qDebug("listening for new socket")
    22. }
    23.  
    24. void TeamStatus::incomingConnection(int socketfd)
    25. {{
    26.  
    27. socket=server->nextPendingConnection();
    28. if((socket->state()==QTcpSocket::ConnectedState))
    29. {
    30. QTcpSocket *socket = new QTcpSocket;
    31. socket->setSocketDescriptor(socketfd);
    32.  
    33. qDebug("new connection1 established");
    34.  
    35. }
    36. {
    37. }
    38. qDebug("new connection1 established");
    39.  
    40. }
    41.  
    42. read_socket();
    43.  
    44.  
    45. }
    46.  
    47.  
    48.  
    49. void TeamStatus::read_socket()
    50. {
    51. QTcpSocket *socket=new QTcpSocket;
    52. socket=(QTcpSocket*) sender();
    53.  
    54. qDebug("after readingy);
    55. QByteArray buffer= socket->readLine();
    56. ... check for the buffer, do something
    57.  
    58. void TeamStatus::write_socket()
    59. {
    60. "How to write the data or send packet to single client or for all clients"
    61. }
    To copy to clipboard, switch view to plain text mode 


    Client.h
    Qt Code:
    1. class QTcpSocket;
    2.  
    3. namespace Ui {
    4. class TCPClient;
    5. }
    6.  
    7. class TCPClient : public QWidget {
    8. Q_OBJECT
    9. public:
    10. TCPClient(QWidget *parent = 0);
    11. ~TCPClient();
    12.  
    13. protected:
    14. void changeEvent(QEvent *e);
    15.  
    16. private:
    17. Ui::TCPClient *ui;
    18. QLineEdit *le,*le1;
    19. QTextEdit *te,*te1;
    20. QPushButton *pb_connect, *pb_disconnect;
    21. QPushButton *pb_send,*pb_send1;
    22. QTcpSocket *socket;
    23. QString CHAT;
    24.  
    25. private slots:
    26. void connecttoserver();
    27. void on_connected();
    28. void write();
    29. void write1();
    30. void DisconnectServer();
    31.  
    32. };
    33.  
    34. #endif // TCPCLIENT_H
    To copy to clipboard, switch view to plain text mode 



    Client.cpp
    Qt Code:
    1. TCPClient::TCPClient(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::TCPClient)
    4. {
    5. ui->setupUi(this);
    6.  
    7. le= new QLineEdit;
    8. le=ui->lineEdit;
    9. le->setDisabled(true);
    10.  
    11. le1=new QLineEdit;
    12. le1=ui->lineEdit_2;
    13. le1->setDisabled(true);
    14.  
    15. te=new QTextEdit;
    16. te=ui->textEdit;
    17. te->setDisabled(true);
    18.  
    19. te1=new QTextEdit;
    20. te1=ui->textEdit_2;
    21. te1->setDisabled(true);
    22.  
    23. pb_connect=new QPushButton;
    24. pb_connect=ui->pushButton;
    25. pb_connect->setText("CONNECT");
    26. pb_connect->setEnabled(true);
    27.  
    28. pb_send=new QPushButton;
    29. pb_send=ui->pushButton_2;
    30. pb_send->setText("Send");
    31. pb_send->setEnabled(false);
    32.  
    33. pb_send1=new QPushButton;
    34. pb_send1=ui->pushButton_3;
    35. pb_send1->setText("SEND");
    36. pb_send1->setEnabled(false);
    37.  
    38. pb_disconnect=new QPushButton;
    39. pb_disconnect=ui->pushButton_4;
    40. pb_disconnect->setEnabled(false);
    41. pb_disconnect->setText("DISCONNECT");
    42.  
    43.  
    44.  
    45. socket=new QTcpSocket(this);
    46.  
    47. connect(pb_connect,SIGNAL(clicked()),this,SLOT(connecttoserver()));
    48. connect(pb_send,SIGNAL(clicked()),this,SLOT(write()));
    49. connect(pb_send1,SIGNAL(clicked()),this,SLOT(write1()));
    50. connect(pb_disconnect,SIGNAL(clicked()),this,SLOT(DisconnectServer()));
    51. connect(socket,SIGNAL(connected()),this,SLOT(on_connected()));
    52. connect(socket,SIGNAL(readyRead()),this,SLOT(read1()));
    53.  
    54. }
    55.  
    56. TCPClient::~TCPClient()
    57. {
    58. delete ui;
    59. }
    60.  
    61. void TCPClient::changeEvent(QEvent *e)
    62. {
    63. QWidget::changeEvent(e);
    64. switch (e->type()) {
    65. case QEvent::LanguageChange:
    66. ui->retranslateUi(this);
    67. break;
    68. default:
    69. break;
    70. }
    71. }
    72.  
    73. void TCPClient::connecttoserver()
    74. {
    75. QHostAddress hAddr;
    76. hAddr.setAddress("192.168.64.55");
    77. socket->connectToHost(hAddr,1234);
    78.  
    79. }
    80.  
    81. void TCPClient::on_connected()
    82. {
    83. pb_connect->setEnabled(false);
    84. pb_send->setEnabled(true);
    85. pb_send1->setEnabled(true);
    86. qDebug("Connection established");
    87. pb_disconnect->setEnabled(true);
    88. le->setEnabled(true);
    89. le1->setEnabled(true);
    90. te->setEnabled(true);
    91. te1->setEnabled(true);
    92. }
    93.  
    94. void TCPClient::write()
    95. {
    96. QString Data="",Data1=this->le->text();
    97. CHAT="1";
    98. Data.append(CHAT);
    99. Data.append(Data1);
    100. socket->write(Data.toUtf8().constData());
    101. qDebug("Client Sent 1 to Server");
    102.  
    103. }
    104. void TCPClient::write1()
    105. {
    106. QString Data="",Data1=this->le->text();
    107. CHAT="2";
    108. Data.append(CHAT);
    109. Data.append(Data1);
    110. socket->write(Data.toUtf8().constData());
    111. qDebug("Client Sent 2 to server");
    112.  
    113. // socket->flush();
    114.  
    115. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Where are you using your listen() method ?
    Check if isListening returns true.
    And check if the newConnection signal is fired when a client connects , to see if you are actually connecting to your server.
    Its not easy to read a code from iphone lol my post might be useless.


    Good Luck.

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

    Default Re: Socket Prog

    Im using Listen() in one of the child window called Team Status. While compiling Im getting Debug msgs of Listen function. Im not gettin debug msg of New client or Connection accepted msg on the Application output window. earlier When i created one server and one client it works fine. when initialise for two or more clients in the server by
    Qt Code:
    1. void TeamStatus::incomingConnection(int socketfd) // Public slot in the teamstatus.H file
    2. {{
    3. QTcpSocket *socket = new QTcpSocket;
    4.  
    5. socket=server->nextPendingConnection();
    6. if((socket->state()==QTcpSocket::ConnectedState))
    7. {
    8. socket->setSocketDescriptor(socketfd);
    9.  
    10. qDebug("new connection1 established");
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    client
    Qt Code:
    1. connect(pb_connect,SIGNAL(clicked()),this,SLOT(connecttoserver()));
    2. connect(socket,SIGNAL(connected()),this,SLOT(on_connected()));
    3. void TCPClient::connecttoserver()
    4. {
    5. QHostAddress hAddr;
    6. hAddr.setAddress("192.168.64.55");
    7. socket->connectToHost(hAddr,1234);
    8.  
    9. void TCPClient::on_connected(int descriptor) //public slot of client.h
    10.  
    11. {
    12. socket=new QTcpSocket(this);
    13. socket->setSocketDescriptor(descriptor);
    14.  
    15.  
    16. connect(pb_send,SIGNAL(clicked()),this,SLOT(write()));
    17. connect(pb_send1,SIGNAL(clicked()),this,SLOT(write1()));
    18. connect(pb_disconnect,SIGNAL(clicked()),this,SLOT(DisconnectServer()));
    19.  
    20. connect(socket,SIGNAL(readyRead()),this,SLOT(read1()));
    21. }
    22.  
    23. void TCPClient::write()
    24. {
    25. QString Data="",Data1=this->le->text();
    26. CHAT="1";
    27. Data.append(CHAT);
    28. Data.append(Data1);
    29. socket->write(Data.toUtf8().constData());
    30. qDebug("Client Sent 1 to Server");
    31.  
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    If can't later also u can look at the code then reply..
    Thanks

  9. #9
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Is the newConnection signal getting fired ?
    Connect it to a slot where you accept the connection.
    Last edited by toufic.dbouk; 13th November 2013 at 09:18.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Quote Originally Posted by toufic.dbouk View Post
    Connect it to a slot where you accept the connection.
    Exactly.

    You can't just create a QTcpServer object and expect that it magically knows how to invoke the function in which you call nextPendingConnection().

    Programming can look like magic but it isn't

    Cheers,
    _

  11. #11
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Socket Prog

    Btw. you have a memory leak here:
    Qt Code:
    1. QTcpSocket *socket = new QTcpSocket; // this object will never be deleted
    2. socket=server->nextPendingConnection();// because you overwrite the only pointer to it here
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Socket Prog

    ya.. I have given a condition If already socket is accepted/connected. process the debug like new connection established
    Qt Code:
    1. socket=server->nextPendingConnection();
    2. if((socket->state()==QTcpSocket::ConnectedState))
    To copy to clipboard, switch view to plain text mode 
    I feel somewhere I'm going wrong when in creating a socket descriptor while assigning for connecting with many clients.
    or using QSet in teamstatus.h for creating more sockets.

  13. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    There is no need to create a socket descriptor, QTcpServer::nextPendingConnection() creates a fully constructed QTcpSocket object.

    Cheers,
    _

  14. #14
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Connect the newConnection signal to a newConnection Slot and accept the connection or use your code :
    Quote Originally Posted by Vivek1982
    Qt Code:
    1. QTcpSocket *socket = new QTcpSocket;
    2. socket=server->nextPendingConnection();
    3. if((socket->state()==QTcpSocket::ConnectedState))
    To copy to clipboard, switch view to plain text mode 
    Good Luck.
    Last edited by toufic.dbouk; 13th November 2013 at 14:32. Reason: Code Tag

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

    Default Re: Socket Prog

    Hi..

    I'm trying built application handling multiple clients by one server Qt Application. I have tried all suggestion to change the code etc.plz have a look on my unsderstanding of this concept of Multiple client in one server. how I'm approaching/trying may be wrong plz correct me.
    Actually Compiling server application and client on same PC. When Server has initiated, first Client will work fine till second client will join, after that first client data is not accepted by server/not reading the first client data.It will stay on to the second client only.
    .SERVER.cpp
    Qt Code:
    1. SERVER::SEVER(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui1(new Ui::SERVER)
    4. {
    5. ui1->setupUi(this);
    6. server=new QTcpServer(this);
    7. connect(team_but,SIGNAL(clicked()),this,SLOT(listen()));
    8. connect(server,SIGNAL(newConnection()),this,SLOT(on_newconn()));
    9.  
    10. void Server::listen()
    11.  
    12.  
    13. {
    14. QHostAddress hAddr;
    15. hAddr.setAddress("192.168.64.55");
    16. server->listen(QHostAddress::Any,1234);
    17. qDebug("Listening to new connection");
    18. }
    19.  
    20. void Server::on_newconn()
    21. {
    22. QTcpSocket *socket= new QTcpSocket;
    23.  
    24. socket=server->nextPendingConnection();
    25. if((socket->state()==QTcpSocket::ConnectedState))
    26. {
    27. qDebug("new connection1 established");
    28. }
    29. connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
    30. }
    31.  
    32. void Server::read_socket()
    33. {
    34. {
    35. QByteArray buffer= socket->readLine();
    36.  
    37. if(buffer.startsWith("1"))
    38. {
    39. QByteArray buf=buffer.mid(1);
    40. qDebug()<<buf;
    41. }
    42. }
    43. else
    44. {
    45. //something to do
    46. }}
    To copy to clipboard, switch view to plain text mode 
    SERVER.H

    Qt Code:
    1. private:
    2. Ui::Server *ui1;
    3. QTcpServer *server;
    4. QTcpSocket *socket;
    5. QPushbutton *team_but
    6.  
    7. private slots:
    8. void listen();
    9. void on_newconn();
    10. void read_socket();
    11. }
    To copy to clipboard, switch view to plain text mode 
    CLIENT.cpp
    Qt Code:
    1. Client::Client(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::Client)
    4. {
    5. ui->setupUi(this);
    6.  
    7. socket=new QTcpSocket(this);
    8. connect(pb_connect,SIGNAL(clicked()),this,SLOT(connecttoserver()));
    9. connect(socket,SIGNAL(connected()),this,SLOT(on_connected()));
    10. }
    11. void Client::connecttoserver()
    12. {
    13. QHostAddress hAddr;
    14. hAddr.setAddress("192.168.64.55");
    15. socket->connectToHost("192.168.64.55",1234);
    16. // socket->connectToHost("192.168.64.52",1234);
    17. }
    18. void Client::on_connected()
    19. {
    20. qDebug("Connected");
    21. }
    22.  
    23. void Client::write()
    24. {
    25. //Data is lineedit text
    26. socket->write(Data.toUtf8().constData());
    27. }
    To copy to clipboard, switch view to plain text mode 

    Client.H
    Qt Code:
    1. private:
    2. Ui::TCPClient *ui;
    3. QTcpSocket *socket;
    4.  
    5. private slots:
    6. void connecttoserver();
    7. void write();
    8. void on_connected();
    To copy to clipboard, switch view to plain text mode 

    i hope Compiling second client on same system(PC) is not issue here.
    Last edited by Vivek1982; 14th November 2013 at 08:10. Reason: missing [code] tags

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    First, get rid of
    Qt Code:
    1. QTcpSocket *socket= new QTcpSocket;
    To copy to clipboard, switch view to plain text mode 
    in Server:n_newconn(). It needlessly creates a QTcpSocket and then loses the pointer to it -> leak

    Qt Code:
    1. QTcpSocket *socket = server->nextPendingConnection();
    To copy to clipboard, switch view to plain text mode 

    in Server::read_socket() you first have to get the socket that emitted the signal, you currently assume that only the last connected client will send data
    Qt Code:
    1. QTcpSocket *socket = qobject_cast<QTcpSocket*>( sender() );
    To copy to clipboard, switch view to plain text mode 

    Alternatively create a "client handler" object for each client's socket, i.e. a class that handles one client connection.

    Cheers,
    _

  17. The following user says thank you to anda_skoa for this useful post:

    Vivek1982 (15th November 2013)

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

    Default Re: Socket Prog

    I think one of your issues is that you expect that if you write something on the server, it should be received by all clients, is that correct? For that you need to iterate over all client sockets and write the same data to all client sockets (once you sort out your problems with establishing proper connections).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    Vivek1982 (15th November 2013)

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

    Default Re: Socket Prog

    Ya.. exactly.. my requirement is many clients will connect to server. Send data/Character as data on socket->write. After server receives a query from client, In general It will the word to all clients.Let me try now, How others can be addresses first, later I will plan for server writing to client, Now I need rectify, server accepting many client issue.

    Alternatively create a "client handler" object for each client's socket, i.e. a class that handles one client connection.
    Cheers,
    this has to be done at server alternatively right

  21. #19
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Yes it should be done on the server side of course. If you recall to my first post i mentioned that you should make a class user that handles the client connection including streams and sockets.

    Good Luck.

  22. The following user says thank you to toufic.dbouk for this useful post:

    Vivek1982 (15th November 2013)

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

    Default Re: Socket Prog

    Dear All,

    I thank you all and Qt Forum.Finally I got the output, Server is able to listen for many clients, based on the data sent. Server is executing small functions, based on the data from client. As earlier discussed. Now I can connect two or more clients. Actually, My complete Application is , get the data from all connected clients. Based on that data sent from each client. Server will send a data/msg to all connected clients.

    Here,Server code is having one socket. while it has to send data for all clients. if I call directly Write(), by QPushbutton activity Is that okay. Or in the write function I need to set some parameter to address all Or in my client application i need to change?

    Qt Code:
    1. connect(pb_clicked,SIGNAL(clicked()),this,SLOT(write());
    2. void Server::write()
    3. {
    4. QString data=this->le->text();
    5. qDebug()<<data;
    6. socket->write(data.toUtf8().constData());
    7. qDebug("server is sending msgs to client");
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 
    Client.cpp
    Qt Code:
    1. connect(pb_clicked,SIGNAL(clicked()),this,SLOT(connectoserver())
    2. connect(socket,SIGNAL(connected()),this,SLOT(on_connected())
    3. connect(socket,SIGNAL(readyRead()),this,SLOT(read()));
    4. void TcpClient::connectoserver()
    5. {
    6. //connect to server
    7. }
    8. void TcpClient::on_connected()
    9. { qDebug("Connected to server");
    10. }
    11. void TcpClient::readsocket()
    12. {
    13. }
    14. void TcpClient::read()
    15. { qDebug("start reading the socket");
    16. QByteArray buffer= socket->readLine();
    17. qDebug("reading the socket ");
    18. te->setText(buffer);
    19. }
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.