[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: QServerSocket: connected, now what?
From:       Thiago Macieira <thiagom () wanadoo ! fr>
Date:       2002-01-28 23:34:13
[Download RAW message or body]

Erik Sigra wrote
>Monday 28 January 2002 23.51 skrev Thiago Macieira:
>> Erik Sigra wrote
>>
>> >I derived a type from QServerSocket and created an object of that type.
>> > It seems to work, because I could connect to it with the program
>> > stream_sender in adasockets-0.1.19/examples. Now what? I can't find any
>> > put/get operations in the documentation for QServerSocket.
>>
>> If you're developing code for KDE, please don't use QSocket or
>> QServerSocket. Instead, prefer our own alternatives (KSocket,
>> KServerSocket and KExtendedSocket)
>
>OK. It would be really helpful with a little example program like
>stream_listener and stream_sender in adasockets (you can type in one and the
>text is printed in the other).

I will get around to it as soon as I have time. But, in the mean time, you can 
take a look at kdelibs/kdecore/tests/kresolvertest.cpp, in function 
localConnect. It uses KExtendedSocket both as server and client to test IPv6 
functionality, but it's much of what you have to do. And there are other uses 
of KExtendedSocket as well as KSocket in the KDE sources.

To make a listening KExtendedSocket:
KExtendedSocket server(QString::null, "myport", 
KExtendedSocket::passiveSocket);
server.listen();

to accept a socket:
KExtendedSocket* client; // must be a pointer
server.accept(client);

To connect to a server:
KExtendedSocket client("hostname", "port");
client.connect();

To send stuff:
client.write(block, blocklen);
etc.

[of course, you should check for errors/success]

if you explore the documentation and the headers, you'll find nifty features 
like setting timeouts for connecting, buffering connections, asychronous 
resolution of hostnames and connection, ...

Good luck

-- 
  Thiago Macieira - UFOT Registry number: 1001
 thiagom@mail.com
   ICQ UIN: 1967141  PGP: 0x8F2978D5 and 0xEA9037A5 (PGP 2.x)
     Registered Linux user #65028


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic