X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/27529614c292a298e67dd8db1f169c94a4df204c..7b90a8f20dd9c1a478f755941795158c38230a80:/samples/wxsocket/client.cpp?ds=sidebyside diff --git a/samples/wxsocket/client.cpp b/samples/wxsocket/client.cpp index e2bfdf6201..ffb17c4de8 100644 --- a/samples/wxsocket/client.cpp +++ b/samples/wxsocket/client.cpp @@ -1,12 +1,12 @@ /* * File: client.cpp * Purpose: wxSocket: client demo - * Author: LAVAUX Guilhem (from minimal.cc) + * Author: LAVAUX Guilhem * Created: June 1997 * Updated: - * Copyright: (c) 1993, AIAI, University of Edinburgh - * (C) 1997, LAVAUX Guilhem + * Copyright: (c) 1997, LAVAUX Guilhem */ + #ifdef __GNUG__ #pragma implementation #pragma interface @@ -22,10 +22,16 @@ #ifndef WX_PRECOMP #include "wx/wx.h" #endif + +#include "wx/wfstream.h" #include "wx/socket.h" #include "wx/url.h" #include "wx/protocol/http.h" +#if defined(__WXMOTIF__) || defined(__WXGTK__) +#include "mondrian.xpm" +#endif + // Define a new application type class MyApp: public wxApp { public: @@ -69,13 +75,13 @@ public: }; // ID for the menu quit command -const SKDEMO_QUIT = 101; -const SKDEMO_CONNECT = 102; -const SKDEMO_TEST1 = 103; -const SKDEMO_TEST2 = 104; -const SKDEMO_CLOSE = 105; -const SKDEMO_TEST3 = 106; -const ID_TEST_CLOSE = 107; +const int SKDEMO_QUIT = 101; +const int SKDEMO_CONNECT = 102; +const int SKDEMO_TEST1 = 103; +const int SKDEMO_TEST2 = 104; +const int SKDEMO_CLOSE = 105; +const int SKDEMO_TEST3 = 106; +const int ID_TEST_CLOSE = 107; IMPLEMENT_APP(MyApp) @@ -88,12 +94,7 @@ bool MyApp::OnInit(void) MyFrame *frame = new MyFrame(); // Give it an icon -#ifdef wx_msw - frame->SetIcon(new wxIcon("mondrian")); -#endif -#ifdef wx_x - frame->SetIcon(new wxIcon("mondrian.xbm")); -#endif + frame->SetIcon(wxICON(mondrian)); // Make a menubar wxMenu *file_menu = new wxMenu(); @@ -106,7 +107,6 @@ bool MyApp::OnInit(void) socket_menu->Append(SKDEMO_CONNECT, "Open session"); socket_menu->AppendSeparator(); socket_menu->Append(SKDEMO_TEST1, "Start test 1"); - socket_menu->Append(SKDEMO_TEST2, "Start test 2"); socket_menu->AppendSeparator(); socket_menu->Append(SKDEMO_CLOSE, "Close session"); socket_menu->AppendSeparator(); @@ -117,7 +117,7 @@ bool MyApp::OnInit(void) frame->SetMenuBar(menu_bar); // Make a panel with a message - (void)new wxPanel(frame, 0, 0, 300, 100); + (void)new wxPanel(frame, -1, wxPoint(0, 0), wxSize(300, 100)); // Show the frame frame->Show(TRUE); @@ -137,7 +137,7 @@ MyFrame::MyFrame(): wxSocketHandler::Master(); sock = new MyClient(); - sock->SetFlags(wxSocketBase::WAITALL); + sock->SetFlags((wxSocketBase::wxSockFlags) (wxSocketBase::WAITALL | wxSocketBase::SPEED)); wxSocketHandler::Master().Register(sock); sock->frame = this; sock->SetNotify(wxSocketBase::REQ_LOST); @@ -162,8 +162,11 @@ void MyFrame::OnExecOpenConnection(wxCommandEvent& WXUNUSED(evt)) if (sock->IsConnected()) sock->Close(); +/* wxString hname = wxGetTextFromUser("Enter the address of the wxSocket Sample Server", "Connect ...", "localhost"); +*/ + wxString hname = "localhost"; addr.Hostname(hname); addr.Service(3000); sock->SetNotify(0); @@ -205,12 +208,12 @@ void MyFrame::UpdateStatus() SetStatusText("", 1); } else { wxIPV4address addr; - char s[100]; + wxChar s[100]; sock->GetPeer(addr); - sprintf(s, "Connected to %s", (const char *)addr.Hostname()); + wxSprintf(s, _T("Connected to %s"), WXSTRINGCAST addr.Hostname()); SetStatusText(s, 0); - sprintf(s, "Service: %d", addr.Service()); + wxSprintf(s, _T("Service: %d"), addr.Service()); SetStatusText(s, 1); } } @@ -220,35 +223,41 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt)) if (!sock->IsConnected()) return; - wxDialog *dlgbox = new wxDialog(this, -1, "Test 1", wxDefaultPosition, wxSize(410, 270)); + wxDialog *dlgbox = new wxDialog(this, -1, "Test 1", wxDefaultPosition, wxSize(414, 250)); wxTextCtrl *text_win = new wxTextCtrl(dlgbox, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE); (void)new wxButton(dlgbox, ID_TEST_CLOSE, "Close", - wxPoint(100, 210), wxSize(100, 40)); - char *buf, *buf2; + wxPoint(100, 210), wxSize(100, -1)); + wxChar *buf, *buf2; dlgbox->Layout(); dlgbox->Show(TRUE); text_win->WriteText("Initializing test 1 ...\n"); + wxYield(); + /* Init */ - buf = copystring("Salut ! Salut ! Salut ! Salut Toto\n"); - buf2 = new char[strlen(buf)+1]; + buf = copystring(_T("Hi ! Hi ! Hi !\n")); + buf2 = new wxChar[wxStrlen(buf)+1]; char c = 0xbe; - sock->WriteMsg(&c, 1); + sock->Write(&c, 1); /* No 1 */ text_win->WriteText("Sending some byte to the server ..."); - sock->Write(buf, strlen(buf)+1); + wxYield(); + sock->Write((char *)buf, wxStrlen(buf)+1); text_win->WriteText("done\n"); + wxYield(); text_win->WriteText("Receiving some byte from the server ..."); - sock->Read(buf2, strlen(buf)+1); + wxYield(); + sock->Read((char *)buf2, wxStrlen(buf)+1); text_win->WriteText("done\n"); + wxYield(); text_win->WriteText("Comparing the two buffers ..."); - if (memcmp(buf, buf2, strlen(buf)+1) != 0) { + if (memcmp(buf, buf2, wxStrlen(buf)+1) != 0) { text_win->WriteText("Fail\n"); sock->Close(); UpdateStatus(); @@ -266,8 +275,8 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt)) void MyFrame::OnExecUrlTest(wxCommandEvent& WXUNUSED(evt)) { - wxString urlname = wxGetTextFromUser("Enter the address of the wxSocket Sample Server", - "Connect ...", "localhost"); + wxString urlname = wxGetTextFromUser("Enter an URL to get", + "URL:", "http://localhost"); wxURL url(urlname); wxInputStream *datas = url.GetInputStream(); @@ -275,7 +284,11 @@ void MyFrame::OnExecUrlTest(wxCommandEvent& WXUNUSED(evt)) if (!datas) wxMessageBox("Error in getting data from the URL.", "Alert !"); else { - wxMessageBox("Success !!", "OK !"); + wxFileOutputStream *str_out = new wxFileOutputStream("test.url"); + str_out->Write(*datas); + + wxMessageBox("Success !! Click on OK to see the text.", "OK"); delete datas; + delete str_out; } }