1 \section{\class{wxSocketBase
}}\label{wxsocketbase
}
3 \wxheading{Derived from
}
5 \helpref{wxEvtHandler
}{wxevthandler
}
7 \wxheading{Include files
}
13 \helpref{GSocket for wxWindows
}{gsocketforwx
}
15 % ---------------------------------------------------------------------------
17 % ---------------------------------------------------------------------------
18 \wxheading{Event handling
}
20 To process events from a socket, use the following event handler macro to direct
22 functions that take a
\helpref{wxSocketEvent
}{wxsocketevent
} argument.
25 \begin{twocollist
}\itemsep=
0pt
26 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{A socket event occured.
}
29 % ---------------------------------------------------------------------------
31 % ---------------------------------------------------------------------------
34 \helpref{wxSocketEvent
}{wxsocketevent
}\\
35 \helpref{wxSocketClient
}{wxsocketclient
}\\
36 \helpref{wxSocketServer
}{wxsocketserver
}
38 % ---------------------------------------------------------------------------
40 % ---------------------------------------------------------------------------
41 \latexignore{\rtfignore{\wxheading{Members
}}}
43 \membersection{wxSocketBase::wxSocketBase
}
45 \func{}{wxSocketBase
}{\void}
47 Default constructor but don't use it, you must use
\helpref{wxSocketClient
}{wxsocketclient
}
48 or
\helpref{wxSocketServer
}{wxsocketserver
}.
50 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}
52 \func{}{\destruct{wxSocketBase
}}{\void}
54 Destroys the wxSocketBase object.
56 % ---------------------------------------------------------------------------
58 % ---------------------------------------------------------------------------
64 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
66 \func{void
}{SetFlags
}{\param{wxSocketBase::wxSockFlags
}{ flags
}}
69 \begin{twocollist
}\itemsep=
0pt
70 \twocolitem{{\bf wxSocketBase::NONE
}}{Normal functionnalities.
}
71 \twocolitem{{\bf wxSocketBase::NOWAIT
}}{Get the available data in the input queue and exit immediately.
}
72 \twocolitem{{\bf wxSocketBase::WAITALL
}}{Wait for all required data unless an error occured.
}
73 \twocolitem{{\bf wxSocketBase::SPEED
}}{Disable the asynchronous IO functionnality.
}
79 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
81 \func{void
}{SetNotify
}{\param{GSocketEventFlags
}{ event_flags
}}
83 SetNotify setups which socket events are to be sent to the event handler.
84 For more information on socket events see
85 \helpref{GSocket events
}{gsocketforwxevents
}.
90 \membersection{wxSocketBase::Notify
}\label{wxsocketbasesetnotify
}
92 \func{void
}{Notify
}{\param{bool
}{ notify
}}
94 Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
101 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
103 \constfunc{bool
}{Ok
}{\void}
105 Returns TRUE if the socket is initialized and ready and FALSE in other
108 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
110 \constfunc{bool
}{Error
}{\void}
112 Returns TRUE if an error occured.
114 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseconnected
}
116 \constfunc{bool
}{IsConnected
}{\void}
118 Returns TRUE if the socket is connected.
120 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
122 \constfunc{bool
}{IsData
}{\void}
124 Returns TRUE if some data is arrived on the socket.
126 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
128 \constfunc{bool
}{IsDisconnected
}{\void}
130 Returns TRUE if the socket is disconnected.
132 \membersection{wxSocketBase::IsNoWait
}\label{wxsocketbasenowait
}
134 \constfunc{bool
}{IsNoWait
}{\void}
136 Returns TRUE if the socket mustn't wait.
138 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
140 \constfunc{size
\_t}{LastCount
}{\void}
142 Returns the number of bytes read or written by the last IO call.
144 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
146 \constfunc{GSocketError
}{LastError
}{\void}
148 Returns an error in the GSocket format. See
\helpref{GSocket errors
}{gsocketforwxerrs
}.
150 % ---------------------------------------------------------------------------
152 % ---------------------------------------------------------------------------
156 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
158 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
160 This function peeks a buffer of
{\it nbytes
} bytes from the socket. Peeking a buffer
161 doesn't delete it from the system socket in-queue.
163 \wxheading{Parameters
}
165 \docparam{buffer
}{Buffer where to put peeked data.
}
167 \docparam{nbytes
}{Number of bytes.
}
169 \wxheading{Return value
}
171 Returns a reference to the current object.
175 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
176 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
177 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
182 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
184 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
186 This function reads a buffer of
{\it nbytes
} bytes from the socket.
188 \wxheading{Parameters
}
190 \docparam{buffer
}{Buffer where to put read data.
}
192 \docparam{nbytes
}{Number of bytes.
}
194 \wxheading{Return value
}
196 Returns a reference to the current object.
198 \wxheading{Remark/Warning
}
200 By default, Read uses an internal asynchronous manager: it will send data when
201 the socket requests them. It is particularly interesting when you enter a long
202 data transfer (e.g. a big file, an image, ...). But it is also buggy when you
203 simply discuss with the peer using user data. In this case, wxSocket prepares
204 itself to send data (Write wait for them to be sent) and during a GUI refresh
205 the user enters new data, which involves a new Read call though the previous
206 isn't finished. Well, in most cases it can work but it might fail too.
207 So I advise you to use the SPEED flag, which disables the asynchronous manager,
208 when you just want to discuss with the peer.
210 This remark is also valid for all IO call.
214 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
215 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
216 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
221 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
223 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
225 This function writes a buffer of
{\it nbytes
} bytes from the socket.
227 \wxheading{Remark/Warning
}
229 By default, Write uses an internal asynchronous manager: it will send data when
230 the socket requests them. It is particularly interesting when you enter a long
231 data transfer (e.g. a big file, an image, ...). But it is also buggy when you
232 simply discuss with the peer using user data. In this case, wxSocket prepares
233 itself to send data (Write wait for them to be sent) and during a GUI refresh
234 the user enters new data, which involves a new Write call though the previous
235 isn't finished. Well, in most cases it can work but it might fail too.
236 So I advise you to use the SPEED flag, which disables the asynchronous manager,
237 when you just want to discuss with the peer.
239 \wxheading{Parameters
}
241 \docparam{buffer
}{Buffer where to get the data to write.
}
243 \docparam{nbytes
}{Number of bytes.
}
245 \wxheading{Return value
}
247 Returns a reference to the current object.
251 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
252 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
253 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
258 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
260 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
262 This function writes a buffer of
{\it nbytes
} bytes from the socket. But it
263 writes a short header before so that ReadMsg can alloc the right size for
264 the buffer. So a buffer sent with WriteMsg
{\bf must
} be read with ReadMsg.
266 \wxheading{Parameters
}
268 \docparam{buffer
}{Buffer where to put data peeked.
}
270 \docparam{nbytes
}{Number of bytes.
}
272 \wxheading{Return value
}
274 Returns a reference to the current object.
278 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
279 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
280 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
281 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
286 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
288 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
290 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
291 to the function isn't big enough, the function filled it and then discard the
292 bytes left. This function always wait for the buffer to be entirely filled.
294 \wxheading{Parameters
}
296 \docparam{buffer
}{Buffer where to put read data.
}
298 \docparam{nbytes
}{Number of bytes allocated for the buffer.
}
300 \wxheading{Return value
}
302 Returns a reference to the current object.
306 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
307 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
308 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
309 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
314 \membersection{wxSocketBase::UnRead
}\label{wxsocketbaseunread
}
316 \func{wxSocketBase\&
}{UnRead
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
318 This function unreads a buffer. It means that the buffer is put in the top
319 of the incoming queue. But, it is put also at the end of all unread buffers.
320 It is useful for sockets because we can't seek it.
322 \wxheading{Parameters
}
324 \docparam{buffer
}{Buffer to be unread.
}
326 \docparam{nbytes
}{Number of bytes.
}
328 \wxheading{Return value
}
330 Returns a reference to the current object.
334 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
335 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
336 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
341 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
343 \func{wxSocketBase\&
}{Discard
}{\void}
345 This function simply deletes all bytes in the incoming queue. This function
348 % ---------------------------------------------------------------------------
350 % ---------------------------------------------------------------------------
351 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
353 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
355 This function waits for an event: it could be an incoming byte, the possibility
356 for the client to write, a lost connection, an incoming connection, an
357 established connection.
359 \wxheading{Parameters
}
361 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
363 \docparam{microsecond
}{Number of microseconds to wait.
}
365 \wxheading{Return value
}
367 Returns TRUE if an event occured, FALSE if the timeout was reached.
371 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
372 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
373 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
378 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
380 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
382 This function waits for a read event.
384 \wxheading{Parameters
}
386 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
388 \docparam{microsecond
}{Number of microseconds to wait.
}
390 \wxheading{Return value
}
392 Returns TRUE if a byte arrived, FALSE if the timeout was reached.
396 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
}\\
397 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
398 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
403 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
405 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
407 This function waits for a write event.
409 \wxheading{Parameters
}
411 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
413 \docparam{microsecond
}{Number of microseconds to wait.
}
415 \wxheading{Return value
}
417 Returns TRUE if a write event occured, FALSE if the timeout was reached.
421 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
}\\
422 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
423 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
428 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
430 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
432 This function waits for a "lost" event. For instance, the peer may have closed
433 the connection, or the connection may have been broken.
435 \wxheading{Parameters
}
437 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
439 \docparam{microsecond
}{Number of microseconds to wait.
}
441 \wxheading{Return value
}
443 Returns TRUE if a "lost" event occured, FALSE if the timeout was reached.
447 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
448 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
449 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
454 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
456 \func{void
}{RestoreState
}{\void}
458 This function restores a previously saved state.
462 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
464 % ---------------------------------------------------------------------------
466 % ---------------------------------------------------------------------------
470 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
472 \func{void
}{SaveState
}{\void}
474 This function saves the current state of the socket object in a stack:
475 actually it saves all flags and the state of the asynchronous callbacks.
479 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
481 % ---------------------------------------------------------------------------
483 % ---------------------------------------------------------------------------
484 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
486 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
488 Sets an event handler to be called when a socket event occured.
490 \wxheading{Parameters
}
492 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
494 \docparam{id
}{The id of socket event.
}
498 \helpref{wxSocketEvent
}{wxsocketevent
}
500 % ---------------------------------------------------------------------------
501 % CLASS wxSocketClient
502 % ---------------------------------------------------------------------------
503 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
505 \wxheading{Derived from
}
507 \helpref{wxSocketBase
}{wxsocketbase
}
509 \wxheading{Include files
}
513 % ---------------------------------------------------------------------------
515 % ---------------------------------------------------------------------------
519 \membersection{wxSocketClient::wxSocketClient
}
521 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
523 Constructs a new wxSocketClient.
525 \wxheading{Parameters
}
527 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
532 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
534 \func{}{\destruct{wxSocketClient
}}{\void}
536 Destroys a wxSocketClient object.
541 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
543 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
545 Connects to a server using the specified address. If
{\it wait
} is TRUE, Connect
546 will wait for the socket ready to send or receive data.
548 \wxheading{Parameters
}
550 \docparam{address
}{Address of the server.
}
552 \docparam{wait
}{If true, waits for the connection to be ready.
}
554 \wxheading{Return value
}
556 Returns TRUE if the connection is established and no error occurs.
560 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
}
565 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
567 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ microseconds =
0}}
569 Wait for a "connect" event.
573 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
} for a detailed description.
575 % ---------------------------------------------------------------------------
576 % CLASS: wxSocketEvent
577 % ---------------------------------------------------------------------------
578 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
580 This event class contains information about socket events.
582 \wxheading{Derived from
}
584 \helpref{wxEvent
}{wxevent
}
586 \wxheading{Include files
}
590 \wxheading{Event table macros
}
592 To process a socket event, use these event handler macros to direct input to member
593 functions that take a wxSocketEvent argument.
596 \begin{twocollist
}\itemsep=
0pt
597 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
602 \helpref{wxSocketBase
}{wxsocketbase
},
\rtfsp
603 \helpref{wxSocketClient
}{wxsocketclient
},
\rtfsp
604 \helpref{wxSocketServer
}{wxsocketserver
}
606 \latexignore{\rtfignore{\wxheading{Members
}}}
608 \membersection{wxSocketEvent::wxSocketEvent
}
610 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
614 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
616 \constfunc{GSocketEvent
}{SocketEvent
}{\void}
618 Returns the socket event type.
620 % ---------------------------------------------------------------------------
621 % CLASS: wxSocketServer
622 % ---------------------------------------------------------------------------
623 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
625 \wxheading{Derived from
}
627 \helpref{wxSocketBase
}{wxsocketbase
}
629 \wxheading{Include files
}
633 % ---------------------------------------------------------------------------
635 % ---------------------------------------------------------------------------
636 \latexignore{\rtfignore{\wxheading{Members
}}}
641 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
643 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
645 Constructs a new wxSocketServer.
647 \wxheading{Parameters
}
649 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
651 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
656 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
658 \func{}{\destruct{wxSocketServer
}}{\void}
660 Destroys a wxSocketServer object (it doesn't close the accepted connection).
665 \membersection{wxSocketServer::Accept
}
667 \func{wxSocketBase *
}{Accept
}{\void}
669 Creates a new object wxSocketBase and accepts an incoming connection.
{\bf Warning !
} This function will block the GUI.
671 \wxheading{Return value
}
673 Returns an opened socket connection.
677 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
682 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
684 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
}}
686 Accept an incoming connection using the specified socket object.
687 This is useful when someone wants to inherit wxSocketBase.
689 \wxheading{Parameters
}
691 \docparam{socket
}{Socket to be initialized
}
693 \wxheading{Return value
}
695 Returns TRUE if no error occurs, else FALSE.