X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e2a6f23364aefcd5095dc6558e3ab8144363fa96..9a98a85452729f479bad8538738ee899a0b1aa34:/samples/wxsocket/client.cpp diff --git a/samples/wxsocket/client.cpp b/samples/wxsocket/client.cpp index e4a57fba5e..646aabfe8c 100644 --- a/samples/wxsocket/client.cpp +++ b/samples/wxsocket/client.cpp @@ -3,7 +3,7 @@ * Purpose: wxSocket: client demo * Author: LAVAUX Guilhem * Created: June 1997 - * Updated: + * CVS ID: $Id$ * Copyright: (c) 1997, LAVAUX Guilhem */ @@ -23,9 +23,11 @@ #include "wx/wx.h" #endif +#include "wx/wfstream.h" #include "wx/socket.h" #include "wx/url.h" #include "wx/protocol/http.h" +#include "wx/thread.h" #if defined(__WXMOTIF__) || defined(__WXGTK__) #include "mondrian.xpm" @@ -136,7 +138,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); @@ -204,12 +206,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); } } @@ -225,7 +227,7 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt)) wxTE_MULTILINE); (void)new wxButton(dlgbox, ID_TEST_CLOSE, "Close", wxPoint(100, 210), wxSize(100, -1)); - char *buf, *buf2; + wxChar *buf, *buf2; dlgbox->Layout(); dlgbox->Show(TRUE); @@ -235,21 +237,25 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt)) 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(); @@ -273,10 +279,16 @@ void MyFrame::OnExecUrlTest(wxCommandEvent& WXUNUSED(evt)) wxURL url(urlname); wxInputStream *datas = url.GetInputStream(); - if (!datas) - wxMessageBox("Error in getting data from the URL.", "Alert !"); - else { - wxMessageBox("Success !! Click on OK to see the text.", "OK"); + if (!datas) { + wxString error; + error.Printf(_T("Error in getting data from the URL. (error = %d)"), url.GetError()); + wxMessageBox(error, "Alert !"); + } else { + wxFileOutputStream *str_out = new wxFileOutputStream("test.url"); + str_out->Write(*datas); + + wxMessageBox(_T("Success !! Click on OK to see the text."), "OK"); delete datas; + delete str_out; } }