1 \section{\class{wxSocketBase
}}\label{wxsocketbase
}
3 \wxheading{Derived from
}
5 \helpref{wxEvtHandler
}{wxevthandler
}
7 % ---------------------------------------------------------------------------
9 % ---------------------------------------------------------------------------
10 \wxheading{Event handling
}
12 To process events from a socket, use the following event handler macro to direct
14 functions that take a
\helpref{wxSocketEvent
}{wxsocketevent
} argument.
17 \begin{twocollist
}\itemsep=
0pt
18 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{A socket event occured.
}
21 % ---------------------------------------------------------------------------
23 % ---------------------------------------------------------------------------
26 \helpref{wxSocketEvent
}{wxsocketevent
},
\helpref{wxSocketClient
}{wxsocketclient
},
\helpref{wxSocketServer
}{wxsocketserver
}
28 % ---------------------------------------------------------------------------
30 % ---------------------------------------------------------------------------
31 \latexignore{\rtfignore{\wxheading{Members
}}}
33 \membersection{wxSocketBase::wxSocketBase
}
35 \func{}{wxSocketBase
}{\void}
37 Default constructor but don't use it, you must use
\helpref{wxSocketClient
}{wxsocketclient
}
38 or
\helpref{wxSocketServer
}{wxsocketserver
}.
40 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}
42 \func{}{\destruct{wxSocketBase
}}{\void}
44 Destroys the wxSocketBase object.
46 % ---------------------------------------------------------------------------
48 % ---------------------------------------------------------------------------
50 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
52 \constfunc{bool
}{Ok
}{\void}
54 Returns TRUE if the socket is initialized and ready and FALSE in other
57 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
59 \constfunc{bool
}{Error
}{\void}
61 Returns TRUE if an error occured.
63 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseconnected
}
65 \constfunc{bool
}{IsConnected
}{\void}
67 Returns TRUE if the socket is connected.
69 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
71 \constfunc{bool
}{IsData
}{\void}
73 Returns TRUE if some data is arrived on the socket.
75 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
77 \constfunc{bool
}{IsDisconnected
}{\void}
79 Returns TRUE if the socket is disconnected.
81 \membersection{wxSocketBase::IsNoWait
}\label{wxsocketbasenowait
}
83 \constfunc{bool
}{IsNoWait
}{\void}
85 Returns TRUE if the socket mustn't wait.
87 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
89 \constfunc{size
\_t}{LastCount
}{\void}
91 Returns the number of bytes read or written by the last IO call.
93 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
95 \constfunc{int
}{LastError
}{\void}
97 Returns an error in the errno format (see your C programmer's guide).
99 % ---------------------------------------------------------------------------
101 % ---------------------------------------------------------------------------
105 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
107 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
109 This function peeks a buffer of
{\it nbytes
} bytes from the socket. Peeking a buffer
110 doesn't delete it from the system socket in-queue.
112 \wxheading{Parameters
}
114 \docparam{buffer
}{Buffer where to put peeked data.
}
116 \docparam{nbytes
}{Number of bytes.
}
118 \wxheading{Return value
}
120 Returns a reference to the current object.
124 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
125 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
126 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
131 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
133 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
135 This function reads a buffer of
{\it nbytes
} bytes from the socket.
137 \wxheading{Parameters
}
139 \docparam{buffer
}{Buffer where to put read data.
}
141 \docparam{nbytes
}{Number of bytes.
}
143 \wxheading{Return value
}
145 Returns a reference to the current object.
149 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
150 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
151 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
153 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
155 \func{void
}{SetFlags
}{\param{wxSockFlags
}{ flags
}}
162 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
164 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
166 This function writes a buffer of
{\it nbytes
} bytes from the socket.
168 \wxheading{Parameters
}
170 \docparam{buffer
}{Buffer where to get the data to write.
}
172 \docparam{nbytes
}{Number of bytes.
}
174 \wxheading{Return value
}
176 Returns a reference to the current object.
180 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
181 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
182 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
187 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
189 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
191 This function writes a buffer of
{\it nbytes
} bytes from the socket. But it
192 writes a short header before so that ReadMsg can alloc the right size for
193 the buffer. So a buffer sent with WriteMsg
{\bf must
} be read with ReadMsg.
195 \wxheading{Parameters
}
197 \docparam{buffer
}{Buffer where to put data peeked.
}
199 \docparam{nbytes
}{Number of bytes.
}
201 \wxheading{Return value
}
203 Returns a reference to the current object.
207 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
208 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
209 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
210 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
215 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
217 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
219 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
220 to the function isn't big enough, the function filled it and then discard the
221 bytes left. This function always wait for the buffer to be entirely filled.
223 \wxheading{Parameters
}
225 \docparam{buffer
}{Buffer where to put read data.
}
227 \docparam{nbytes
}{Number of bytes allocated for the buffer.
}
229 \wxheading{Return value
}
231 Returns a reference to the current object.
235 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
236 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
237 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
238 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
243 \membersection{wxSocketBase::UnRead
}\label{wxsocketbaseunread
}
245 \func{wxSocketBase\&
}{UnRead
}{\param{const char *
}{ buffer
},
\param{size
\_t}{ nbytes
}}
247 This function unreads a buffer. It means that the buffer is put in the top
248 of the incoming queue. But, it is put also at the end of all unread buffers.
249 It is useful for sockets because we can't seek it.
251 \wxheading{Parameters
}
253 \docparam{buffer
}{Buffer to be unread.
}
255 \docparam{nbytes
}{Number of bytes.
}
257 \wxheading{Return value
}
259 Returns a reference to the current object.
263 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
264 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
265 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
270 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
272 \func{wxSocketBase\&
}{Discard
}{\void}
274 This function simply deletes all bytes in the incoming queue. This function
277 % ---------------------------------------------------------------------------
279 % ---------------------------------------------------------------------------
280 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
282 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
284 This function waits for an event: it could be an incoming byte, the possibility
285 for the client to write, a lost connection, an incoming connection, an
286 established connection.
288 \wxheading{Parameters
}
290 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
292 \docparam{microsecond
}{Number of microseconds to wait.
}
294 \wxheading{Return value
}
296 Returns TRUE if an event occured, FALSE if the timeout was reached.
300 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
301 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
302 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
307 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
309 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
311 This function waits for a read event.
313 \wxheading{Parameters
}
315 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
317 \docparam{microsecond
}{Number of microseconds to wait.
}
319 \wxheading{Return value
}
321 Returns TRUE if a byte arrived, FALSE if the timeout was reached.
325 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
326 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
327 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
332 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
334 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
336 This function waits for a write event.
338 \wxheading{Parameters
}
340 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
342 \docparam{microsecond
}{Number of microseconds to wait.
}
344 \wxheading{Return value
}
346 Returns TRUE if a write event occured, FALSE if the timeout was reached.
350 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
351 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
352 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
357 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
359 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ microsecond =
0}}
361 This function waits for a "lost" event. For instance, the peer may have closed
362 the connection, or the connection may have been broken.
364 \wxheading{Parameters
}
366 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
368 \docparam{microsecond
}{Number of microseconds to wait.
}
370 \wxheading{Return value
}
372 Returns TRUE if a "lost" event occured, FALSE if the timeout was reached.
376 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
377 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
378 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
383 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
385 \func{void
}{RestoreState
}{\void}
387 This function restores a previously saved state.
391 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
393 % ---------------------------------------------------------------------------
395 % ---------------------------------------------------------------------------
399 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
401 \func{void
}{SaveState
}{\void}
403 This function saves the current state of the socket object in a stack:
404 actually it saves all flags and the state of the asynchronous callbacks.
408 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
410 % ---------------------------------------------------------------------------
412 % ---------------------------------------------------------------------------
413 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
415 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
417 Sets an event handler to be called when a socket event occured.
419 \wxheading{Parameters
}
421 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
423 \docparam{id
}{The id of socket event.
}
427 \helpref{wxSocketEvent
}{wxsocketevent
}
429 % ---------------------------------------------------------------------------
430 % CLASS wxSocketClient
431 % ---------------------------------------------------------------------------
432 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
434 \wxheading{Derived from
}
436 \helpref{wxSocketBase
}{wxsocketbase
}
438 % ---------------------------------------------------------------------------
440 % ---------------------------------------------------------------------------
444 \membersection{wxSocketClient::wxSocketClient
}
446 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
448 Constructs a new wxSocketClient.
450 {\bf Warning !
} The created socket client needs to be registered to a socket handler (See
\helpref{wxSocketHandler
}{wxsockethandler
}).
452 \wxheading{Parameters
}
454 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
459 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
461 \func{}{\destruct{wxSocketClient
}}{\void}
463 Destructs a wxSocketClient object.
468 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
470 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
472 Connects to a server using the specified address. If
{\it wait
} is TRUE, Connect
473 will wait for the socket ready to send or receive data.
475 \wxheading{Parameters
}
477 \docparam{address
}{Address of the server.
}
479 \docparam{wait
}{If true, waits for the connection to be ready.
}
481 \wxheading{Return value
}
483 Returns TRUE if the connection is established and no error occurs.
487 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
}
492 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
494 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ microseconds =
0}}
496 Wait for a "connect" event.
500 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
} for a detailed description.
502 % ---------------------------------------------------------------------------
503 % CLASS: wxSocketEvent
504 % ---------------------------------------------------------------------------
505 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
507 This event class contains information about socket events.
509 \wxheading{Derived from
}
511 \helpref{wxEvent
}{wxevent
}
513 \wxheading{Event table macros
}
515 To process a socket event, use these event handler macros to direct input to member
516 functions that take a wxSocketEvent argument.
519 \begin{twocollist
}\itemsep=
0pt
520 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
525 \helpref{wxSocketHandler
}{wxsockethandler
},
\rtfsp
526 \helpref{wxSocketBase
}{wxsocketbase
},
\rtfsp
527 \helpref{wxSocketClient
}{wxsocketclient
},
\rtfsp
528 \helpref{wxSocketServer
}{wxsocketserver
}
530 \latexignore{\rtfignore{\wxheading{Members
}}}
532 \membersection{wxSocketEvent::wxSocketEvent
}
534 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
538 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
540 \constfunc{wxSocketBase::wxRequestEvent
}{SocketEvent
}{\void}
542 Returns the socket event type.
544 % ---------------------------------------------------------------------------
545 % CLASS: wxSocketHandler
546 % ---------------------------------------------------------------------------
547 \section{\class{wxSocketHandler
}}\label{wxsockethandler
}
549 \wxheading{Derived from
}
551 \helpref{wxObject
}{wxobject
}
553 % ---------------------------------------------------------------------------
555 % ---------------------------------------------------------------------------
556 \latexignore{\rtfignore{\wxheading{Members
}}}
561 \membersection{wxSocketHandler::wxSocketHandler
}
563 \func{}{wxSocketHandler
}{\void}
565 Constructs a new wxSocketHandler.
567 It is advised to use
\helpref{wxSocketHandler::Master
}{wxsockethandlermaster
} to
568 get a socket handler. But creating a socket handler is useful to group
574 \membersection{wxSocketHandler::
\destruct{wxSocketHandler
}}
576 \func{}{\destruct{wxSocketHandler
}}{\void}
578 Destructs a wxSocketHandler object.
583 \membersection{wxSocketHandler::Register
}
585 \func{void
}{Register
}{\param{wxSocketBase *
}{socket
}}
587 Register a socket: if it is already registered in this handler it will just
590 \wxheading{Parameters
}
592 \docparam{socket
}{Socket to be registered.
}
597 \membersection{wxSocketHandler::UnRegister
}
599 \func{void
}{UnRegister
}{\param{wxSocketBase *
}{socket
}}
601 UnRegister a socket: if it isn't registered in this handler it will just
604 \wxheading{Parameters
}
606 \docparam{socket
}{Socket to be unregistered.
}
611 \membersection{wxSocketHandler::Count
}
613 \constfunc{unsigned long
}{Count
}{\void}
615 Returns the number of sockets registered in the handler.
617 \wxheading{Return value
}
619 Number of sockets registered.
624 \membersection{wxSocketHandler::CreateServer
}
626 \func{wxSocketServer *
}{CreateServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSocketBase::wxSockFlags
}{ flags = wxSocketbase::NONE
}}
628 Creates a new wxSocketServer object. The object is automatically registered
629 to the current socket handler.
630 For a detailed description of the parameters, see
\helpref{wxSocketServer::wxSocketServer
}{wxsocketserverconstr
}.
632 \wxheading{Return value
}
634 Returns a new socket server.
639 \membersection{wxSocketHandler::CreateClient
}
641 \func{wxSocketServer *
}{CreateClient
}{\param{wxSocketBase::wxSockFlags
}{ flags = wxSocketbase::NONE
}}
643 Creates a new wxSocketClient object. The object is automatically registered
644 to the current socket handler.
646 For a detailed description of the parameters, see
\helpref{wxSocketClient::Connect
}{wxsocketclientconnect
}.
648 \wxheading{Return value
}
650 Returns a new socket client.
655 \membersection{wxSocketHandler::Master
}\label{wxsockethandlermaster
}
657 \func{static wxSocketHandler\&
}{Master
}{\void}
659 Returns a default socket handler.
664 \membersection{wxSocketHandler::Wait
}
666 \func{int
}{Wait
}{\param{long
}{ seconds
},
\param{long
}{ microseconds
}}
668 Wait for an event on all registered sockets.
670 \wxheading{Parameters
}
672 \docparam{seconds
}{Number of seconds to wait. By default, it waits infinitely.
}
674 \docparam{microsecond
}{Number of microseconds to wait.
}
676 \wxheading{Return value
}
678 Returns
0 if a timeout occured, else the number of events detected.
682 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
}
687 \membersection{wxSocketHandler::YieldSock
}
689 \func{void
}{YieldSock
}{\void}
691 Execute pending requests in all registered sockets.
692 % ---------------------------------------------------------------------------
693 % CLASS: wxSocketServer
694 % ---------------------------------------------------------------------------
695 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
697 \wxheading{Derived from
}
699 \helpref{wxSocketBase
}{wxsocketbase
}
701 % ---------------------------------------------------------------------------
703 % ---------------------------------------------------------------------------
704 \latexignore{\rtfignore{\wxheading{Members
}}}
709 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
711 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
713 Constructs a new wxSocketServer.
715 {\bf Warning !
} The created object needs to be registered to a socket handler
716 (see
\helpref{wxSocketHandler
}{wxsockethandler
}).
718 \wxheading{Parameters
}
720 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
722 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
727 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
729 \func{}{\destruct{wxSocketServer
}}{\void}
731 Destructs a wxSocketServer object (it doesn't close the accepted connection).
736 \membersection{wxSocketServer::Accept
}
738 \func{wxSocketBase *
}{Accept
}{\void}
740 Creates a new object wxSocketBase and accepts an incoming connection.
{\bf Warning !
} This function will block the GUI.
742 \wxheading{Return value
}
744 Returns an opened socket connection.
748 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
753 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
755 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
}}
757 Accept an incoming connection using the specified socket object.
758 This is useful when someone wants to inherit wxSocketBase.
760 \wxheading{Parameters
}
762 \docparam{socket
}{Socket to be initialized
}
764 \wxheading{Return value
}
766 Returns TRUE if no error occurs, else FALSE.