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 /////////////////////////////////////////////////////////////////////////////
19 #if defined(__GNUG__) && !defined(__APPLE__)
20 #pragma interface "sckipc.h"
25 #if wxUSE_SOCKETS && wxUSE_IPC
27 #include "wx/ipcbase.h"
28 #include "wx/socket.h"
29 #include "wx/sckstrm.h"
30 #include "wx/datstrm.h"
33 * Mini-DDE implementation
35 Most transactions involve a topic name and an item name (choose these
36 as befits your application).
40 - ask the server to execute commands (data) associated with a topic
41 - request data from server by topic and item
42 - poke data into the server
43 - ask the server to start an advice loop on topic/item
44 - ask the server to stop an advice loop
48 - respond to execute, request, poke and advice start/stop
49 - send advise data to client
51 Note that this limits the server in the ways it can send data to the
52 client, i.e. it can't send unsolicited information.
56 class WXDLLIMPEXP_NET wxTCPServer
;
57 class WXDLLIMPEXP_NET wxTCPClient
;
59 class WXDLLIMPEXP_NET wxTCPConnection
: public wxConnectionBase
61 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
64 wxTCPConnection(wxChar
*buffer
, int size
);
66 virtual ~wxTCPConnection();
68 // Calls that CLIENT can make
69 virtual bool Execute(const wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
70 virtual wxChar
*Request(const wxString
& item
, int *size
= NULL
, wxIPCFormat format
= wxIPC_TEXT
);
71 virtual bool Poke(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
72 virtual bool StartAdvise(const wxString
& item
);
73 virtual bool StopAdvise(const wxString
& item
);
75 // Calls that SERVER can make
76 virtual bool Advise(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
78 // Calls that both can make
79 virtual bool Disconnect(void);
81 // Callbacks to BOTH - override at will
82 // Default behaviour is to delete connection and return TRUE
83 virtual bool OnDisconnect(void) { delete this; return TRUE
; }
85 // To enable the compressor (NOTE: not implemented!)
86 void Compress(bool on
);
90 wxSocketStream
*m_sockstrm
;
91 wxDataInputStream
*m_codeci
;
92 wxDataOutputStream
*m_codeco
;
95 friend class wxTCPServer
;
96 friend class wxTCPClient
;
97 friend class wxTCPEventHandler
;
101 // We're hiding an Execute method in ConnectionBase
103 virtual bool Execute(const wxString
& str
)
104 { return Execute(str
, -1, wxIPC_TEXT
); }
106 DECLARE_NO_COPY_CLASS(wxTCPConnection
)
109 class wxTCPServer
: public wxServerBase
111 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
114 wxTCPConnection
*topLevelConnection
;
117 virtual ~wxTCPServer();
119 // Returns FALSE on error (e.g. port number is already in use)
120 virtual bool Create(const wxString
& serverName
);
122 // Callbacks to SERVER - override at will
123 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
126 wxSocketServer
*m_server
;
129 // the name of the file associated to the Unix domain socket, may be empty
131 #endif // __UNIX_LIKE__
133 DECLARE_NO_COPY_CLASS(wxTCPServer
)
136 class wxTCPClient
: public wxClientBase
138 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
142 virtual ~wxTCPClient();
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 #endif // wxUSE_SOCKETS && wxUSE_IPC
157 #endif // _WX_SCKIPC_H