+ char *msg1;
+ char *msg2;
+ size_t len;
+
+ // Disable socket menu entries (exception: Close Session)
+ m_busy = TRUE;
+ UpdateStatusBar();
+
+ m_text->AppendText(_T("\n=== Test 2 begins ===\n"));
+
+ // Tell the server which test we are running
+ char c = 0xCE;
+ m_sock->Write(&c, 1);
+
+ // Here we use ReadMsg and WriteMsg to send messages with
+ // a header with size information. Also, the reception is
+ // event triggered, so we test input events as well.
+ //
+ // We need to set no flags here (ReadMsg and WriteMsg are
+ // not affected by flags)
+ //
+ m_sock->SetFlags(wxSOCKET_WAITALL);
+
+ wxString s = wxGetTextFromUser(
+ _T("Enter an arbitrary string to send to the server:"),
+ _T("Test 2 ..."),
+ _T("Yes I like wxWindows!"));
+
+ msg1 = (char *)s.c_str();
+ len = wxStrlen(msg1) + 1;
+ msg2 = (char *)malloc(len);
+
+ m_text->AppendText(_T("Sending the string with WriteMsg ..."));
+ m_sock->WriteMsg(msg1, len);
+ m_text->AppendText(m_sock->Error() ? _T("failed !\n") : _T("done\n"));
+ m_text->AppendText(_T("Waiting for an event (timeout = 2 sec)\n"));
+
+ // Wait until data available (will also return if the connection is lost)
+ m_sock->WaitForRead(2);
+
+ if (m_sock->IsData())
+ {
+ m_text->AppendText(_T("Reading the string back with ReadMsg ..."));
+ m_sock->ReadMsg(msg2, len);
+ m_text->AppendText(m_sock->Error() ? _T("failed !\n") : _T("done\n"));
+ m_text->AppendText(_T("Comparing the two buffers ..."));
+ if (memcmp(msg1, msg2, len) != 0)
+ {
+ m_text->AppendText(_T("failed!\n"));
+ m_text->AppendText(_T("Test 2 failed !\n"));
+ }
+ else
+ {
+ m_text->AppendText(_T("done\n"));
+ m_text->AppendText(_T("Test 2 passed !\n"));
+ }
+ }
+ else
+ m_text->AppendText(_T("Timeout ! Test 2 failed.\n"));
+
+ m_text->AppendText(_T("=== Test 2 ends ===\n"));