hi,
i like to implement simple client -server model of qt. but unfortunately i dint get proper output. its totally runtime error. please help me to find out..
here my server code which will receive the output once connected with client :
code:
#include "widget.h"
#include "ui_widget.h"
#include "QtNetwork/qabstractsocket.h"
#include "QtNetwork/qtcpserver.h"
#include "QtNetwork/qtcpsocket.h"
#include "QtNetwork/QHostAddress"
#include "QMessageBox"
#include "QDebug"
#include "QDataStream"
#include "stdio.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
int s;
serversocket=new QTcpServer();
client=new QTcpSocket();
serversocket->listen(QHostAddress::Any,5639);
QObject::connect(serversocket,SIGNAL(newConnection ()),this,SLOT(memberofserver()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::memberofserver()
{
QTcpSocket *client = serversocket->nextPendingConnection();
QObject::connect(client,SIGNAL(disconnected()),cli ent,SLOT(deleteLater()));
QDataStream in(client);
in.setVersion(QDataStream::Qt_4_0);
QString data;
in >> data;
ui->text1->setText(data);
}
here my client code which will send data to server once it got connected :
code :
#include "widget.h"
#include "ui_widget.h"
#include "QMessageBox"
#include "QAbstractSocket"
#include "QTcpSocket"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
client1=new QTcpSocket(this);
client1->connectToHost("ipaddr...",5639);
if(client1->state()==QAbstractSocket::ConnectedState)
QMessageBox::information(this,tr("client"),tr("suc cessfullyconnected"));
else
QMessageBox::information(this,tr("server"),tr("uns uccessfulcompletion"));
client1->write("heysuper",20);
}
Widget::~Widget()
{
delete ui;
}
please help me to find out soon
thanks in advance,
shakthi
Bookmarks