프로그래밍과 잡담

[Qt] 간단한 Hello World 서버 본문

프로그래밍/Qt

[Qt] 간단한 Hello World 서버

크레온 2009. 8. 14. 22:24
#include <QtGui/QWidget>
#include <QTcpServer>
#include <QTcpSocket>

class ReplyServer : public QTcpServer
{
    Q_OBJECT

public:
    ReplyServer(QObject *parent = 0);
    ~ReplyServer();

   
public slots:
    void makeConnection();
    void send();
    void disconnect();
   
private:
    QTcpSocket* tcp;
  
};


ReplyServer::ReplyServer(QObject *parent)
    : QTcpServer(parent)
{
    connect(this,SIGNAL(newConnection()), SLOT(makeConnection()));
    quint16 port = 5000;
    listen(QHostAddress::Any,port);     // 이곳이 중요..
}

위에 두개정도만 잘 하면 되고 나머지는 알아서 만들면 된다.

Qt는 뭔가 네트워크 프로그래밍이 좀 어려운거 같다.
C로 만드는걸 보면 소켓생성하고 bind listen accpt 함수들을 사용하면 된다. 하지만 이 Qt 뭔가 좀 어렵다.




반응형
Comments