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
10 // Copyright: (c) Julian Smart 1993
11 // (c) Guilhem Lavaux 1997, 1998
12 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
13 // Licence: wxWindows licence
14 /////////////////////////////////////////////////////////////////////////////
21 #if wxUSE_SOCKETS && wxUSE_IPC
23 #include "wx/ipcbase.h"
24 #include "wx/socket.h"
25 #include "wx/sckstrm.h"
26 #include "wx/datstrm.h"
29 * Mini-DDE implementation
31 Most transactions involve a topic name and an item name (choose these
32 as befits your application).
36 - ask the server to execute commands (data) associated with a topic
37 - request data from server by topic and item
38 - poke data into the server
39 - ask the server to start an advice loop on topic/item
40 - ask the server to stop an advice loop
44 - respond to execute, request, poke and advice start/stop
45 - send advise data to client
47 Note that this limits the server in the ways it can send data to the
48 client, i.e. it can't send unsolicited information.
52 class WXDLLIMPEXP_FWD_NET wxTCPServer
;
53 class WXDLLIMPEXP_FWD_NET wxTCPClient
;
55 class wxIPCSocketStreams
;
57 class WXDLLIMPEXP_NET wxTCPConnection
: public wxConnectionBase
60 wxTCPConnection() { Init(); }
61 wxTCPConnection(void *buffer
, size_t size
)
62 : wxConnectionBase(buffer
, size
)
67 virtual ~wxTCPConnection();
69 // implement base class pure virtual methods
70 virtual const void *Request(const wxString
& item
,
72 wxIPCFormat format
= wxIPC_TEXT
);
73 virtual bool StartAdvise(const wxString
& item
);
74 virtual bool StopAdvise(const wxString
& item
);
75 virtual bool Disconnect(void);
77 // Will be used in the future to enable the compression but does nothing
79 void Compress(bool on
);
83 virtual bool DoExecute(const void *data
, size_t size
, wxIPCFormat format
);
84 virtual bool DoPoke(const wxString
& item
, const void *data
, size_t size
,
86 virtual bool DoAdvise(const wxString
& item
, const void *data
, size_t size
,
90 // notice that all the members below are only initialized once the
91 // connection is made, i.e. in MakeConnection() for the client objects and
92 // after OnAcceptConnection() in the server ones
94 // the underlying socket (wxSocketClient for IPC client and wxSocketServer
98 // various streams that we use
99 wxIPCSocketStreams
*m_streams
;
101 // the topic of this connection
105 // common part of both ctors
108 friend class wxTCPServer
;
109 friend class wxTCPClient
;
110 friend class wxTCPEventHandler
;
112 wxDECLARE_NO_COPY_CLASS(wxTCPConnection
);
113 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
116 class WXDLLIMPEXP_NET wxTCPServer
: public wxServerBase
120 virtual ~wxTCPServer();
122 // Returns false on error (e.g. port number is already in use)
123 virtual bool Create(const wxString
& serverName
);
125 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
128 wxSocketServer
*m_server
;
131 // the name of the file associated to the Unix domain socket, may be empty
133 #endif // __UNIX_LIKE__
135 wxDECLARE_NO_COPY_CLASS(wxTCPServer
);
136 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
139 class WXDLLIMPEXP_NET wxTCPClient
: public wxClientBase
144 virtual bool ValidHost(const wxString
& host
);
146 // Call this to make a connection. Returns NULL if cannot.
147 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
148 const wxString
& server
,
149 const wxString
& topic
);
151 // Callbacks to CLIENT - override at will
152 virtual wxConnectionBase
*OnMakeConnection();
155 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
158 #endif // wxUSE_SOCKETS && wxUSE_IPC
160 #endif // _WX_SCKIPC_H