D> I am looking for an example or guide for using wxTCPClient and
D> wxTCPConnection. So far I have only found sckipc.cpp, which is a bit
D> overwhelming.
What about samples/ipc?
D> How do I make my own OnMakeConnection and how should it return a TCP
D> connection?
You don't need to override OnMakeConnection(), it's possible to just use
the base wxConnection class as is. If you do want to define a custom
connection class, then derive it from wxConnection and return a new
instance of it from OnMakeConnection().
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
> How do I get a wxTCPClient object to talk to a wxTCPConnection object?
> How does one know about the other?
The client object isn't a connection endpoint. It's a connection
establishment machine. It creates the connection object and hands that to
you to continue talking to the remote peer. Once the connection is
established, you don't need the client object.
I've not used these classes nor dug through the code, and am just going by
what I'm seeing in the docs for wxTCPClient. The initial description
doesn't really make sense given the way the use of the classes is described.
Vadim, does the wxTCPClient hold any state for the connections it creates?
Can it be discarded after it connects?
I'd have to dig through the source to see how that works. I always do that
when the documentation doesn't make sense and I want to understand the
logic.
My guess is that the client object starts the connection handshake, and
when it completes, a Connection object will be created and passed back to
the caller. But I don't know if there's a state machine inside or it's all
synchronous. You'll have to look at the source to know for sure. (Or wait
for someone more knowledgable to chime in.)
OnMakeConnection is used for custom derived classes to pass back a custom
derived Connection class.
I suggest grepping the Client sources to see what calls it.
KP> --On Wednesday, November 18, 2009 12:57 PM -0800 Daniel
KP> <danw...@gmail.com> wrote:
KP>
KP> > Thanks for the info. In the ipc example I don't understand the use of
KP> > OnMakeConnection. In the example OnMakeConnection is implemented with
KP> > just one command: return new MyConnection. Return to what?
KP> > OnMakeConnection is not mentioned anywhere else. And with no
KP> > information from the Client control sent to MyConnection? I thought
KP> > OnMakeConnection was an event.
KP>
KP> I'd have to dig through the source to see how that works. I always do that
KP> when the documentation doesn't make sense and I want to understand the
KP> logic.
I think documentation does make sense in this case, see
http://docs.wxwidgets.org/trunk/classwx_t_c_p_client.html#23359471eace5dca485aad4a3e24680f
What is exactly unclear with it?
KP> OnMakeConnection is used for custom derived classes to pass back a custom
KP> derived Connection class.
Exactly.
KP> I suggest grepping the Client sources to see what calls it.
This can always be instructive but I don't see why would it be necessary.
> I think documentation does make sense in this case, see
>
> http://docs.wxwidgets.org/trunk/classwx_t_c_p_client.html#23359471eace5dc
> a485aad4a3e24680f
>
> What is exactly unclear with it?
>
> KP> OnMakeConnection is used for custom derived classes to pass back a
> custom KP> derived Connection class.
>
> Exactly.
>
> KP> I suggest grepping the Client sources to see what calls it.
>
> This can always be instructive but I don't see why would it be necessary.
Ah, you're linking to the doxygen docs, and my googles always turn up the
old docs, which often leave a lot to spelunking the sources for
clarification. (For example, I'm digging through <wx/fileconf.h> to figure
out where I need to write the file with a text editor to recreate the use
of regedit in a Linux enviroment.)
In the docs for TCP IPC, even under doxygen, there's no explicit statement
of the object lifecycles. A quick check of the code suggests that
wxTCPClient is not referenced by wxTCPConnection, so the factory object
only needs to exist until the connection object is created. (Is this true
for all the other subclasses? That should probably be mentioned.)
I don't see an ownership relationship in a brief skim of the code. Where do
you see that?
The wxTCPClient object is a factory that produces wxTCPConnection objects.
It's not really a "client". The wxTCPConnection is the actual client that
you interact with to communicate with the network peer.
KP> In the docs for TCP IPC, even under doxygen, there's no explicit statement
KP> of the object lifecycles. A quick check of the code suggests that
KP> wxTCPClient is not referenced by wxTCPConnection, so the factory object
KP> only needs to exist until the connection object is created. (Is this true
KP> for all the other subclasses? That should probably be mentioned.)
wxClient is not (only) the factory object. It's first and foremost the
client abstraction and is not used just to create connections but also, and
mainly, to provide real IPC methods. So it doesn't make sense to delete it
but keep the connection as you wouldn't be able to use it anyhow.
I guess the docs do need to be updated with a short overview of the
classes relationships. I don't have the time to do it myself but I'd gladly
apply any patches doing it, of course. Basically they just need to say that
you need to create a wxClient or wxServer depending on the endpoint you're
implementing and that you _may_ define your own connection class if
necessary but that this is entirely optional and that in any case you never
use the connection directly.
>> I don't see an ownership relationship in a brief skim of the code. Where
>> do you see that?
>>
>
> Look at client.h line 106 in ipc example.
Ok, that's only in the sample, not in the base class. The base class
doesn't have an ownership relationship to the connection(s) it creates. It
can create many connections and doesn't hold pointers to any of them.
> wxClient is not (only) the factory object. It's first and foremost the
> client abstraction and is not used just to create connections but also,
> and mainly, to provide real IPC methods. So it doesn't make sense to
> delete it but keep the connection as you wouldn't be able to use it
> anyhow.
<http://docs.wxwidgets.org/trunk/classwx_t_c_p_client.html#23359471eace5dc>
Side question: Why doesn't doxygen show wxClientBase as the base class in
the hierarchy?
wx*Client provides MakeConnection (the factory method), OnMakeConnection
(an internal callback for the implementer), and ValidHost (a utility method
handy for input validation before the factory is invoked). None of those
apply to an active connection.
All the methods that you would use once the connection is established are
in the wx*Connection object.
While not practical to do now, the client class would better be named
wx*ClientConnectionFactory, because it creates client connections. Once
established, a connection doesn't have any further need for the wx*Client
object that created it.