[Interest] QTcpServer - One connection per port
konrad at silmor.de
Tue Jun 12 21:48:57 CEST 2012
On Tuesday 12 June 2012 11:14:54 Gopalakrishna Bhat wrote:
> I am trying to use QTcpServer to accept connection from only one client at
> a time, but i'm not able to do so.
> I tried setting setMaxPendingConnections to one but then
> also waitForConnected on the second client returned true. I want
> waitForConnected to return true only for the first client.
> Any I idea what I am doing wrong?
Two ideas: either you are solving the problem on the wrong layer, the wrong
way or you are solving the wrong problem.
As Thiago wrote: it is not possible to tell the OS to accept only one
connection. It's in the spec for TCP: it assumes that servers actually want to
serve data to clients...
Wrong layer: some protocols solve this problem by accepting the connection,
then sending the second client a message that they do not intend to allow this
connection to proceed and optionally a reason for this rejection, then they
close the connection.
The wrong way: how about as soon as a new client connects - kick the old
client. This may be easier to implement for some problem spaces. Of course it
produces new problems, like the possibility of (a different kind of) DoS. It
may be worth considering both variants and then decide which one has fewer
Wrong problem: the need for having only one connection is often a serious
design problem in the protocol. There are hundreds of scenarios how single-
connection protocols can screw up, for example if a network link is lost the
server may not notice the problem for hours - during that time you will not be
able to connect another client. It may be a good idea to try to fix the
protocol to handle multiple concurrent connections.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/interest/attachments/20120612/27888f15/attachment.bin
More information about the Interest