Skip to navigation
   
Dave F's Blog
QT Sockets - what it says on the tin

By Dave F in Reader

Posted in QT, Coding on October 15, 2009 at 11:24 am

Permalink | Author Profile

It’s surprising when things actually work like they should, so surprising that “It does what it says on the tin” is an effective advertising slogan! So it was a pleasant surprise when I chucked together some code to work with sockets using QT. In the past I have had to mess about with Winsock or Berkeley Sockets, set up local addresses, convert port numbers to n/w format (cue big endian / little endian innuendos), do unspeakable things with ioctl’s…. with QT it was just
SendData( char *hostname,  int port ,
                char *buf; int len){

    QTcpSocket socket ;
    char recv[1]; 

    // could set up events with signals and slots but not needed here

    socket_.connectToHost(hostname, port);
    socket.waitForConnected(TM_OUT);
    if (!socket.connected())
            return FAILED;

    if (socket.write(buf, len) < 0)
        return FAILED;

    socket.waitForReadyRead(TM_OUT);
    if (socket.bytesAvailable())
        return FAILED;

    if (socket.read(recv, 1)!=1 || recv[0]!=HOST_OK_HANDSHAKE)
        return FAILED;

    // could close but destructor will anyway!
}
And it works on Windows, Linux and Mac! Check it out at http://qt.nokia.com/ 

Now as long as my boss doesn’t read this I can tell him it took days….
12345
Not yet rated
Loading ... Loading ...

Previous Post | Next Post

 
 
Comments

Comment by micro sd speicherkarten - October 16, 2009 on 7:21 am

This is great.I was wondering this stuff only.It is very useful for me.Thanks for sharing it here…

Comment by Wow gold - October 16, 2009 on 7:58 am

Very cool! Congrats on the pairing.

Trackback by Jon Samide - February 9, 2012 on 7:47 am

greenpeace australia campaigns…

[…]various points where Judge Rodgers may have failed to exercise […]…

Trackback by Homepage - February 29, 2012 on 2:43 pm

… [Trackback] …

[…] There you will find 87277 more Infos: itpro.co.uk/blogs-archive/davef/2009/10/15/qt-sockets-what-it-says-on-the-tin/ […] …

Trackback by gutrolacitd - April 21, 2012 on 8:23 pm

You should check this out…

[…] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well […]……

Trackback by triloketrio - May 8, 2012 on 7:45 pm

Websites we think you should visit…

[…]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[…]……

Make a comment

* required

* required

We stop spam using reCaptcha.
Type the words below and click Submit Comment.

Advertisement