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"
24 #include "wx/ipcbase.h"
25 #include "wx/socket.h"
26 #include "wx/sckstrm.h"
27 #include "wx/datstrm.h"
30 * Mini-DDE implementation
32 Most transactions involve a topic name and an item name (choose these
33 as befits your application).
37 - ask the server to execute commands (data) associated with a topic
38 - request data from server by topic and item
39 - poke data into the server
40 - ask the server to start an advice loop on topic/item
41 - ask the server to stop an advice loop
45 - respond to execute, request, poke and advice start/stop
46 - send advise data to client
48 Note that this limits the server in the ways it can send data to the
49 client, i.e. it can't send unsolicited information.
53 class WXDLLEXPORT wxTCPServer
;
54 class WXDLLEXPORT wxTCPClient
;
56 class WXDLLEXPORT wxTCPConnection
: public wxConnectionBase
58 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
60 wxTCPConnection(char *buffer
, int size
);
62 virtual ~wxTCPConnection();
64 // Calls that CLIENT can make
65 virtual bool Execute(const wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
66 virtual char *Request(const wxString
& item
, int *size
= NULL
, wxIPCFormat format
= wxIPC_TEXT
);
67 virtual bool Poke(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
68 virtual bool StartAdvise(const wxString
& item
);
69 virtual bool StopAdvise(const wxString
& item
);
71 // Calls that SERVER can make
72 virtual bool Advise(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
);
74 // Calls that both can make
75 virtual bool Disconnect(void);
77 // Default behaviour is to delete connection and return TRUE
78 virtual bool OnDisconnect(void) { delete this; return TRUE
; }
80 // To enable the compressor
81 void Compress(bool on
);
85 wxSocketStream
*m_sockstrm
;
86 wxDataInputStream
*m_codeci
;
87 wxDataOutputStream
*m_codeco
;
90 friend class wxTCPServer
;
91 friend class wxTCPClient
;
92 friend void Client_OnRequest(wxSocketBase
&,
93 wxSocketNotify
, char *);
94 friend void Server_OnRequest(wxSocketServer
&,
95 wxSocketNotify
, char *);
99 // We're hiding an Execute method in ConnectionBase
101 virtual bool Execute(const wxString
& str
)
102 { return Execute(str
, -1, wxIPC_TEXT
); }
105 class wxTCPServer
: public wxServerBase
107 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
110 wxTCPConnection
*topLevelConnection
;
113 virtual ~wxTCPServer();
115 // Returns FALSE if can't create server (e.g. port number is already in use)
116 virtual bool Create(const wxString
& server_name
);
117 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
120 class wxTCPClient
: public wxClientBase
122 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
126 virtual ~wxTCPClient();
128 virtual bool ValidHost(const wxString
& host
);
129 // Call this to make a connection.
130 // Returns NULL if cannot.
131 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
132 const wxString
& server
,
133 const wxString
& topic
);
135 // Tailor this to return own connection.
136 virtual wxConnectionBase
*OnMakeConnection();