- if (!sock->IsConnected())
- return;
-
- 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, -1));
- wxChar *buf, *buf2;
-
- dlgbox->Layout();
- dlgbox->Show(TRUE);
-
- text_win->WriteText("Initializing test 1 ...\n");
-
- wxYield();
-
- /* Init */
- buf = copystring(_T("Hi ! Hi ! Hi !\n"));
- buf2 = new wxChar[wxStrlen(buf)+1];
- char c = 0xbe;
- sock->Write(&c, 1);
-
- /* No 1 */
- text_win->WriteText("Sending some byte to the server ...");
- wxYield();
- sock->Write((char *)buf, wxStrlen(buf)+1);
- text_win->WriteText("done\n");
- wxYield();
- text_win->WriteText("Receiving some byte from the server ...");
- 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, wxStrlen(buf)+1) != 0) {
- text_win->WriteText("Fail\n");
- sock->Close();
- UpdateStatus();
- } else
- text_win->WriteText("done\nTest 1A passed !\n");
-
- /* No 2 */
- sock->SetEventHandler(*this, SKDEMO_SCK);
- sock->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
- sock->Notify(TRUE);
-
- text_win->WriteText("Test 1B: sending bytes to the server\n");
- wxYield();
- sock->Write((char *)buf, wxStrlen(buf)+1);
- text_win->WriteText("Waiting for incoming bytes (timeout = 2 sec) ...");
- wxYield();
-
- m_good = 2;
-
- MyFrameSocketTimer timer;
-
- timer.m_var = &m_good;
- timer.Start(2000, TRUE);
-
- while (m_good == 2)
- wxYield();
-
- if (!m_good) {
- text_win->WriteText("Timeout ! Failed.\n");
- sock->Close();
- UpdateStatus();
- } else
- text_win->WriteText("Success.");
-
- sock->Read((char *)buf2, wxStrlen(buf)+1);
-
- dlgbox->Layout();
- dlgbox->ShowModal();