+ wxIPV4address addrPeer;
+ addrPeer.Hostname(hostname);
+ addrPeer.Service(3000);
+
+ wxLogMessage("Testing UDP with peer at %s:%u",
+ addrPeer.IPAddress(), addrPeer.Service());
+
+ char buf[] = "Uryyb sebz pyvrag!";
+ if ( sock.SendTo(addrPeer, buf, sizeof(buf)).LastCount() != sizeof(buf) )
+ {
+ wxLogMessage("ERROR: failed to send data");
+ return;
+ }
+
+ if ( sock.RecvFrom(addrPeer, buf, sizeof(buf)).LastCount() != sizeof(buf) )
+ {
+ wxLogMessage("ERROR: failed to receive data");
+ return;
+ }
+
+ wxLogMessage("Received \"%s\" from %s:%u.",
+ wxString::From8BitData(buf, sock.LastCount()),
+ addrPeer.IPAddress(), addrPeer.Service());
+}
+
+#if wxUSE_URL
+
+void MyFrame::OnTestURL(wxCommandEvent& WXUNUSED(event))
+{
+ // Ask for the URL
+ static wxString s_urlname("http://www.google.com/");
+ wxString urlname = wxGetTextFromUser
+ (
+ _("Enter an URL to get"),
+ _("URL:"),
+ s_urlname
+ );
+ if ( urlname.empty() )
+ return; // cancelled by user
+
+ s_urlname = urlname;
+
+
+ TestLogger logtest("URL");
+
+ // Parse the URL
+ wxURL url(urlname);
+ if ( url.GetError() != wxURL_NOERR )
+ {
+ wxLogError("Failed to parse URL \"%s\"", urlname);
+ return;
+ }
+
+ // Try to get the input stream (connects to the given URL)
+ wxLogMessage("Establishing connection to \"%s\"...", urlname);
+ const std::auto_ptr<wxInputStream> data(url.GetInputStream());
+ if ( !data.get() )
+ {
+ wxLogError("Failed to retrieve URL \"%s\"", urlname);
+ return;
+ }
+
+ // Print the contents type and file size
+ wxLogMessage("Contents type: %s\nFile size: %i\nStarting to download...",
+ url.GetProtocol().GetContentType(),
+ data->GetSize());
+
+ // Get the data
+ wxStringOutputStream sout;
+ if ( data->Read(sout).GetLastError() != wxSTREAM_EOF )
+ {
+ wxLogError("Error reading the input stream.");
+ }
+
+ wxLogMessage("Text retrieved from URL \"%s\" follows:\n%s",
+ urlname, sout.GetString());
+}
+
+#endif // wxUSE_URL
+
+void MyFrame::OnSocketEvent(wxSocketEvent& event)
+{
+ switch ( event.GetSocketEvent() )
+ {
+ case wxSOCKET_INPUT:
+ wxLogMessage("Input available on the socket");
+ break;
+
+ case wxSOCKET_LOST:
+ wxLogMessage("Socket connection was unexpectedly lost.");
+ UpdateStatusBar();
+ break;
+
+ case wxSOCKET_CONNECTION:
+ wxLogMessage("... socket is now connected.");
+ UpdateStatusBar();
+ break;
+
+ default:
+ wxLogMessage("Unknown socket event!!!");
+ break;
+ }