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_NET wxTCPServer
;
53 class WXDLLIMPEXP_NET wxTCPClient
;
55 class WXDLLIMPEXP_NET wxTCPConnection
: public wxConnectionBase
57 DECLARE_DYNAMIC_CLASS(wxTCPConnection
)
60 wxTCPConnection(wxChar
*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 wxChar
*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 // Callbacks to BOTH - override at will
78 // Default behaviour is to delete connection and return true
79 virtual bool OnDisconnect(void) { delete this; return true; }
81 // To enable the compressor (NOTE: not implemented!)
82 void Compress(bool on
);
84 // unhide the Execute overload from wxConnectionBase
85 // FIXME-UTF8: change Execute() to DoExecute() to avoid having to do this;
86 // don't use c_str() below after removing ANSI build
87 virtual bool Execute(const wxString
& str
)
88 { return Execute(str
.c_str(), -1, wxIPC_TEXT
); }
92 wxSocketStream
*m_sockstrm
;
93 wxDataInputStream
*m_codeci
;
94 wxDataOutputStream
*m_codeco
;
97 friend class wxTCPServer
;
98 friend class wxTCPClient
;
99 friend class wxTCPEventHandler
;
101 DECLARE_NO_COPY_CLASS(wxTCPConnection
)
104 class WXDLLIMPEXP_NET wxTCPServer
: public wxServerBase
107 wxTCPConnection
*topLevelConnection
;
110 virtual ~wxTCPServer();
112 // Returns false on error (e.g. port number is already in use)
113 virtual bool Create(const wxString
& serverName
);
115 // Callbacks to SERVER - override at will
116 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
);
119 wxSocketServer
*m_server
;
122 // the name of the file associated to the Unix domain socket, may be empty
124 #endif // __UNIX_LIKE__
126 DECLARE_NO_COPY_CLASS(wxTCPServer
)
127 DECLARE_DYNAMIC_CLASS(wxTCPServer
)
130 class WXDLLIMPEXP_NET wxTCPClient
: public wxClientBase
134 virtual ~wxTCPClient();
136 virtual bool ValidHost(const wxString
& host
);
138 // Call this to make a connection. Returns NULL if cannot.
139 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
140 const wxString
& server
,
141 const wxString
& topic
);
143 // Callbacks to CLIENT - override at will
144 virtual wxConnectionBase
*OnMakeConnection();
147 DECLARE_DYNAMIC_CLASS(wxTCPClient
)
150 #endif // wxUSE_SOCKETS && wxUSE_IPC
152 #endif // _WX_SCKIPC_H