1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Interprocess communication implementation (wxSocket version)
4 // Author: Julian Smart
5 // Modified by: Guilhem Lavaux (big rewrite) May 1997, 1998
6 // Guillermo Rodriguez (updated for wxSocket v2) Jan 2000
7 // (callbacks deprecated) Mar 2000
9 // Copyright: (c) Julian Smart 1993
10 // (c) Guilhem Lavaux 1997, 1998
11 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
20 #if wxUSE_SOCKETS && wxUSE_IPC
22 #include "wx/ipcbase.h"
23 #include "wx/socket.h"
24 #include "wx/sckstrm.h"
25 #include "wx/datstrm.h"
28 * Mini-DDE implementation
30 Most transactions involve a topic name and an item name (choose these
31 as befits your application).
35 - ask the server to execute commands (data) associated with a topic
36 - request data from server by topic and item
37 - poke data into the server
38 - ask the server to start an advice loop on topic/item
39 - ask the server to stop an advice loop
43 - respond to execute, request, poke and advice start/stop
44 - send advise data to client
46 Note that this limits the server in the ways it can send data to the
47 client, i.e. it can't send unsolicited information.
51 class WXDLLIMPEXP_FWD_NET wxTCPServer
;
52 class WXDLLIMPEXP_FWD_NET wxTCPClient
;
54 class wxIPCSocketStreams
;
56 class WXDLLIMPEXP_NET wxTCPConnection
: public wxConnectionBase
59 wxTCPConnection() { Init(); }
60 wxTCPConnection(void *buffer
, size_t size
)
61 : wxConnectionBase(buffer
, size
)
66 virtual ~wxTCPConnection();
68 // implement base class pure virtual methods
69 virtual const void *Request(const wxString
& item
,
71 wxIPCFormat format
= wxIPC_TEXT
);
72 virtual bool StartAdvise(const wxString
& item
);
73 virtual bool StopAdvise(const wxString
& item
);
74 virtual bool Disconnect(void);
76 // Will be used in the future to enable the compression but does nothing
78 void Compress(bool on
);
82 virtual bool DoExecute(const void *data
, size_t size
, wxIPCFormat format
);
83 virtual bool DoPoke(const wxString
& item
, const void *data
, size_t size
,
85 virtual bool DoAdvise(const wxString
& item
, const void *data
, size_t size
,
89 // notice that all the members below are only initialized once the
90 // connection is made, i.e. in MakeConnection() for the client objects and
91 // after OnAcceptConnection() in the server ones
93 // the underlying socket (wxSocketClient for IPC client and wxSocketServer
97 // various streams that we use
98 wxIPCSocketStreams
*m_streams
;
100 // the topic of this connection
104 // common part of both ctors
107 friend class wxTCPServer
;
108 friend class wxTCPClient
;
109 friend class wxTCPEventHandler
;
111 wxDECLARE_NO_COPY_CLASS(wxTCPConnection
);
112 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
115 class WXDLLIMPEXP_NET wxTCPServer
: public wxServerBase
119 virtual ~wxTCPServer();
121 // Returns false on error (e.g. port number is already in use)
122 virtual bool Create(const wxString
& serverName
);
124 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
127 wxSocketServer
*m_server
;
130 // the name of the file associated to the Unix domain socket, may be empty
132 #endif // __UNIX_LIKE__
134 wxDECLARE_NO_COPY_CLASS(wxTCPServer
);
135 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
138 class WXDLLIMPEXP_NET wxTCPClient
: public wxClientBase
143 virtual bool ValidHost(const wxString
& host
);
145 // Call this to make a connection. Returns NULL if cannot.
146 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
147 const wxString
& server
,
148 const wxString
& topic
);
150 // Callbacks to CLIENT - override at will
151 virtual wxConnectionBase
*OnMakeConnection();
154 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
157 #endif // wxUSE_SOCKETS && wxUSE_IPC
159 #endif // _WX_SCKIPC_H