- /* this routine gets called from within the
- waiting socket thread, i.e. here we are
- not in the main GUI thread and thus we
- must not call any GUI function here. */
- /* Wrong ! This routine is called by the main GUI thread
- because the main GUI thread received a signal from the other
- thread using wxEvent::ProcessThreadEvent */
-
- wxSocketBase *sock = evt.Socket();
-
- wxPrintf(_T("OnSockRequest OK\n"));
- wxPrintf(_T("OnSockRequest (event = %d)\n"),evt.SocketEvent());
- switch (evt.SocketEvent()) {
- case GSOCK_INPUT:
- unsigned char c;
-
- sock->Read((char *)&c, 1);
- if (c == 0xbe)
- ExecTest1(sock);
-
- break;
- case GSOCK_LOST:
- wxPrintf(_T("Destroying socket\n"));
- wxPendingDelete.Append(sock);
- UpdateStatus(-1);
- return;
- break;
- default:
- wxPrintf(_T("Invalid event !\n"));
- }
- wxPrintf(_T("OnSockRequest Exiting\n"));
+ // Give the frame an icon
+ SetIcon(wxICON(mondrian));
+
+ // Make menus
+ m_menuFile = new wxMenu();
+ m_menuFile->Append(SERVER_ABOUT, _T("&About...\tCtrl-A"), _T("Show about dialog"));
+ m_menuFile->AppendSeparator();
+ m_menuFile->Append(SERVER_QUIT, _T("E&xit\tAlt-X"), _T("Quit server"));
+
+ // Append menus to the menubar
+ m_menuBar = new wxMenuBar();
+ m_menuBar->Append(m_menuFile, _T("&File"));
+ SetMenuBar(m_menuBar);
+
+ // Status bar
+ CreateStatusBar(2);
+
+ // Make a panel with a textctrl in it
+ m_panel = new wxPanel(this, -1, wxPoint(0, 0), GetClientSize());
+ m_text = new wxTextCtrl(m_panel, -1,
+ _T("Welcome to wxSocket demo: Server\n"),
+ wxPoint(0, 0), m_panel->GetClientSize(),
+ wxTE_MULTILINE | wxTE_READONLY);
+
+ // Create the socket
+ wxIPV4address addr;
+ addr.Service(3000);
+
+ m_server = new wxSocketServer(addr);
+ m_server->SetEventHandler(*this, SERVER_ID);
+ m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
+ m_server->Notify(TRUE);
+
+ // We use Ok() here to see if the server is really listening
+ if (m_server->Ok())
+ m_text->AppendText(_T("Server listening.\n\n"));
+ else
+ m_text->AppendText(_T("Could not listen at the specified port !\n\n"));
+
+ m_busy = FALSE;
+ m_numClients = 0;
+ UpdateStatusBar();