X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b62ca03d6f409732ca63c68a79b7ae81444222e5..c687b303a5040da07009ea93504121aeec56682a:/samples/sockets/client.cpp diff --git a/samples/sockets/client.cpp b/samples/sockets/client.cpp index 9ca5518df8..6acab6716f 100644 --- a/samples/sockets/client.cpp +++ b/samples/sockets/client.cpp @@ -18,8 +18,8 @@ // -------------------------------------------------------------------------- #if defined(__GNUG__) && !defined(__APPLE__) -# pragma implementation "client.cpp" -# pragma interface "client.cpp" + #pragma implementation + #pragma interface #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -29,7 +29,7 @@ # pragma hdrstop #endif -// for all others, include the necessary headers +// for all others, include the necessary headers #ifndef WX_PRECOMP # include "wx/wx.h" #endif @@ -76,8 +76,10 @@ public: void OnTest3(wxCommandEvent& event); void OnCloseConnection(wxCommandEvent& event); +#if wxUSE_URL // event handlers for Protocols menu void OnTestURL(wxCommandEvent& event); +#endif // event handlers for DatagramSocket menu (stub) void OnDatagram(wxCommandEvent& event); @@ -110,14 +112,16 @@ private: enum { // menu items - CLIENT_QUIT = 1000, - CLIENT_ABOUT, - CLIENT_OPEN, + CLIENT_QUIT = wxID_EXIT, + CLIENT_ABOUT = wxID_ABOUT, + CLIENT_OPEN = 100, CLIENT_TEST1, CLIENT_TEST2, CLIENT_TEST3, CLIENT_CLOSE, +#if wxUSE_URL CLIENT_TESTURL, +#endif CLIENT_DGRAM, // id for socket @@ -137,7 +141,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(CLIENT_TEST3, MyFrame::OnTest3) EVT_MENU(CLIENT_CLOSE, MyFrame::OnCloseConnection) EVT_MENU(CLIENT_DGRAM, MyFrame::OnDatagram) +#if wxUSE_URL EVT_MENU(CLIENT_TESTURL, MyFrame::OnTestURL) +#endif EVT_SOCKET(SOCKET_ID, MyFrame::OnSocketEvent) END_EVENT_TABLE() @@ -194,19 +200,25 @@ MyFrame::MyFrame() : wxFrame((wxFrame *)NULL, wxID_ANY, m_menuDatagramSocket = new wxMenu(); m_menuDatagramSocket->Append(CLIENT_DGRAM, _("Send Datagram"), _("Test UDP sockets")); +#if wxUSE_URL m_menuProtocols = new wxMenu(); m_menuProtocols->Append(CLIENT_TESTURL, _("Test URL"), _("Get data from the specified URL")); +#endif // Append menus to the menubar m_menuBar = new wxMenuBar(); m_menuBar->Append(m_menuFile, _("&File")); m_menuBar->Append(m_menuSocket, _("&SocketClient")); m_menuBar->Append(m_menuDatagramSocket, _("&DatagramSocket")); +#if wxUSE_URL m_menuBar->Append(m_menuProtocols, _("&Protocols")); +#endif SetMenuBar(m_menuBar); +#if wxUSE_STATUSBAR // Status bar CreateStatusBar(2); +#endif // wxUSE_STATUSBAR // Make a textctrl for logging m_text = new wxTextCtrl(this, wxID_ANY, @@ -278,7 +290,7 @@ void MyFrame::OnOpenConnection(wxCommandEvent& WXUNUSED(event)) // // Connect(addr, false) will issue a nonblocking connection request // and return immediately. If the return value is true, then the - // connection has been already succesfully established. If it is + // connection has been already successfully established. If it is // false, you must wait for the request to complete, either with // WaitOnConnect() or by watching wxSOCKET_CONNECTION / LOST // events (please read the documentation). @@ -311,7 +323,7 @@ void MyFrame::OnOpenConnection(wxCommandEvent& WXUNUSED(event)) // // update waitmore if needed. // } // bool success = client->IsConnected(); - // + // // And that's all :-) m_text->AppendText(_("\nTrying to connect (timeout = 10 sec) ...\n")); @@ -326,7 +338,7 @@ void MyFrame::OnOpenConnection(wxCommandEvent& WXUNUSED(event)) m_text->AppendText(_("Failed ! Unable to connect\n")); wxMessageBox(_("Can't connect to the specified host"), _("Alert !")); } - + UpdateStatusBar(); } @@ -361,7 +373,7 @@ void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event)) m_sock->SetFlags(wxSOCKET_WAITALL); buf1 = _("Test string (less than 256 chars!)"); - len = (wxStrlen(buf1) + 1) * sizeof(wxChar); + len = (unsigned char)((wxStrlen(buf1) + 1) * sizeof(wxChar)); buf2 = new wxChar[wxStrlen(buf1) + 1]; m_text->AppendText(_("Sending a test buffer to the server ...")); @@ -441,7 +453,7 @@ void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event)) m_text->AppendText(_("Comparing the two buffers ...")); if (memcmp(msg1, msg2, len) != 0) { - m_text->AppendText(_("failed!\n")); + m_text->AppendText(_("failed!\n")); m_text->AppendText(_("Test 2 failed !\n")); } else @@ -531,6 +543,8 @@ void MyFrame::OnDatagram(wxCommandEvent& WXUNUSED(event)) m_text->AppendText(_("=== Datagram test ends ===\n")); } +#if wxUSE_URL + void MyFrame::OnTestURL(wxCommandEvent& WXUNUSED(event)) { // Note that we are creating a new socket here, so this @@ -571,7 +585,7 @@ void MyFrame::OnTestURL(wxCommandEvent& WXUNUSED(event)) wxYield(); // Get the data - wxFile fileTest(wxT("test.url")); + wxFile fileTest(wxT("test.url"), wxFile::write); wxFileOutputStream sout(fileTest); if (!sout.Ok()) { @@ -588,6 +602,8 @@ void MyFrame::OnTestURL(wxCommandEvent& WXUNUSED(event)) delete data; } +#endif + void MyFrame::OnSocketEvent(wxSocketEvent& event) { wxString s = _("OnSocketEvent: "); @@ -622,7 +638,9 @@ void MyFrame::UpdateStatusBar() s.Printf(_("%s : %d"), (addr.Hostname()).c_str(), addr.Service()); } +#if wxUSE_STATUSBAR SetStatusText(s, 1); +#endif // wxUSE_STATUSBAR m_menuSocket->Enable(CLIENT_OPEN, !m_sock->IsConnected() && !m_busy); m_menuSocket->Enable(CLIENT_TEST1, m_sock->IsConnected() && !m_busy);