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
9 // Copyright: (c) Julian Smart 1993
10 // (c) Guilhem Lavaux 1997, 1998
11 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
19 #pragma interface "sckipc.h"
26 #include "wx/ipcbase.h"
27 #include "wx/socket.h"
28 #include "wx/sckstrm.h"
29 #include "wx/datstrm.h"
32 * Mini-DDE implementation
34 Most transactions involve a topic name and an item name (choose these
35 as befits your application).
39 - ask the server to execute commands (data) associated with a topic
40 - request data from server by topic and item
41 - poke data into the server
42 - ask the server to start an advice loop on topic/item
43 - ask the server to stop an advice loop
47 - respond to execute, request, poke and advice start/stop
48 - send advise data to client
50 Note that this limits the server in the ways it can send data to the
51 client, i.e. it can't send unsolicited information.
55 class WXDLLEXPORT wxTCPServer
;
56 class WXDLLEXPORT wxTCPClient
;
58 class WXDLLEXPORT wxTCPConnection
: public wxConnectionBase
60 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
62 wxTCPConnection(char *buffer
, int size
);
64 virtual ~wxTCPConnection();
66 // Calls that CLIENT can make
67 virtual bool Execute(const wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
68 virtual char *Request(const wxString
& item
, int *size
= NULL
, wxIPCFormat format
= wxIPC_TEXT
);
69 virtual bool Poke(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
70 virtual bool StartAdvise(const wxString
& item
);
71 virtual bool StopAdvise(const wxString
& item
);
73 // Calls that SERVER can make
74 virtual bool Advise(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
76 // Calls that both can make
77 virtual bool Disconnect(void);
79 // Default behaviour is to delete connection and return TRUE
80 virtual bool OnDisconnect(void) { delete this; return TRUE
; }
82 // To enable the compressor
83 void Compress(bool on
);
87 wxSocketStream
*m_sockstrm
;
88 wxDataInputStream
*m_codeci
;
89 wxDataOutputStream
*m_codeco
;
92 friend class wxTCPServer
;
93 friend class wxTCPClient
;
94 friend void Client_OnRequest(wxSocketBase
&,
95 wxSocketNotify
, char *);
96 friend void Server_OnRequest(wxSocketServer
&,
97 wxSocketNotify
, char *);
101 // We're hiding an Execute method in ConnectionBase
103 virtual bool Execute(const wxString
& str
)
104 { return Execute(str
, -1, wxIPC_TEXT
); }
107 class wxTCPServer
: public wxServerBase
109 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
112 wxTCPConnection
*topLevelConnection
;
115 virtual ~wxTCPServer();
117 // Returns FALSE if can't create server (e.g. port number is already in use)
118 virtual bool Create(const wxString
& server_name
);
119 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
122 class wxTCPClient
: public wxClientBase
124 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
128 virtual ~wxTCPClient();
130 virtual bool ValidHost(const wxString
& host
);
131 // Call this to make a connection.
132 // Returns NULL if cannot.
133 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
134 const wxString
& server
,
135 const wxString
& topic
);
137 // Tailor this to return own connection.
138 virtual wxConnectionBase
*OnMakeConnection();
141 #endif // wxUSE_SOCKETS