I am trying to create a VNC client. Right now, I am creating the GUI that will be viewing the remote user's screen. Here is my code so far, I am using wxWidgets 3.2.2:
#include <wx/wx.h> #include <wx/socket.h> #include <iostream> class MyApp : public wxApp { public: virtual bool OnInit(); }; class MyFrame : public wxFrame { public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); void OnConnect(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnSocketEvent(wxSocketEvent& event); private: wxSocketServer m_server; wxSocketBase* m_clientSocket; bool m_connectionReceived; wxDECLARE_EVENT_TABLE(); }; enum { ID_CONNECT = 1, ID_EXIT }; wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_CONNECT, MyFrame::OnConnect) EVT_MENU(ID_EXIT, MyFrame::OnExit) EVT_SOCKET(wxID_ANY, MyFrame::OnSocketEvent) wxEND_EVENT_TABLE() bool MyApp::OnInit() { MyFrame* frame = new MyFrame("wxWidgets Network App", wxPoint(50, 50), wxSize(800, 600)); frame->Show(true); SetTopWindow(frame); return true; } MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(nullptr, wxID_ANY, title, pos, size), m_server(), // Initialize without specifying flags m_clientSocket(nullptr), m_connectionReceived(false) { // Create a menu wxMenu* menuFile = new wxMenu; menuFile->Append(ID_CONNECT, "Connect", "Connect to the client"); menuFile->Append(ID_EXIT, "Exit", "Exit the application"); wxMenuBar* menuBar = new wxMenuBar; menuBar->Append(menuFile, "File"); SetMenuBar(menuBar); CreateStatusBar(); SetStatusText("Waiting for a connection..."); if (!m_server.Ok()) { wxLogError("Failed to set up the server."); } if (!m_server.WaitForAccept(wxSOCKET_WAITALL, -1)) { wxLogError("Failed to wait for incoming connections."); } } void MyFrame::OnConnect(wxCommandEvent& event) { if (!m_connectionReceived) { if (m_clientSocket) { m_connectionReceived = true; SetStatusText("Connection received."); SetTitle("CONNECTION RECEIVED"); } } } void MyFrame::OnExit(wxCommandEvent& event) { Close(true); } void MyFrame::OnSocketEvent(wxSocketEvent& event) { if (event.GetSocket() == &m_server) { if (event.GetSocketEvent() == wxSOCKET_CONNECTION) { m_clientSocket = m_server.Accept(); if (m_clientSocket) { m_connectionReceived = true; SetStatusText("Connection received."); SetTitle("CONNECTION RECEIVED"); } } } } IMPLEMENT_APP(MyApp) I am getting the following errors:
Severity Code Description Project File Line Suppression State Error (active) E0289 no instance of constructor "wxSocketServer::wxSocketServer" matches the argument list VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 50 Severity Code Description Project File Line Suppression State Error C2512 'wxSocketServer::wxSocketServer': no appropriate default constructor available VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 50 Updated my code, now running into this problem:
#include <wx/wx.h> #include <wx/socket.h> #include <iostream> class MyApp : public wxApp { public: virtual bool OnInit(); }; class MyFrame : public wxFrame { public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); void OnConnect(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnSocketEvent(wxSocketEvent& event); private: wxSocketServer m_server; wxSocketBase* m_clientSocket; bool m_connectionReceived; wxDECLARE_EVENT_TABLE(); }; enum { ID_CONNECT = 1, ID_EXIT }; wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_CONNECT, MyFrame::OnConnect) EVT_MENU(ID_EXIT, MyFrame::OnExit) EVT_SOCKET(wxID_ANY, MyFrame::OnSocketEvent) wxEND_EVENT_TABLE() bool MyApp::OnInit() { MyFrame* frame = new MyFrame("wxWidgets Network App", wxPoint(50, 50), wxSize(800, 600)); frame->Show(true); SetTopWindow(frame); return true; } MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(nullptr, wxID_ANY, title, pos, size), m_server(nullptr), m_clientSocket(nullptr), m_connectionReceived(false) { wxIPV4address addr; addr.AnyAddress(); // listen on all adapters unsigned short localListenPort = 64000; // listen on port 64000 addr.Service(localListenPort); m_server = new wxSocketServer(localListenPort); // Create a menu wxMenu* menuFile = new wxMenu; menuFile->Append(ID_CONNECT, "Connect", "Connect to the client"); menuFile->Append(ID_EXIT, "Exit", "Exit the application"); wxMenuBar* menuBar = new wxMenuBar; menuBar->Append(menuFile, "File"); SetMenuBar(menuBar); CreateStatusBar(); SetStatusText("Waiting for a connection..."); if (!m_server.Ok()) { wxLogError("Failed to set up the server."); } if (!m_server.WaitForAccept(wxSOCKET_WAITALL, -1)) { wxLogError("Failed to wait for incoming connections."); } } void MyFrame::OnConnect(wxCommandEvent& event) { if (!m_connectionReceived) { if (m_clientSocket) { m_connectionReceived = true; SetStatusText("Connection received."); SetTitle("CONNECTION RECEIVED"); } } } void MyFrame::OnExit(wxCommandEvent& event) { Close(true); } void MyFrame::OnSocketEvent(wxSocketEvent& event) { if (event.GetSocket() == &m_server) { if (event.GetSocketEvent() == wxSOCKET_CONNECTION) { m_clientSocket = m_server.Accept(); if (m_clientSocket) { m_connectionReceived = true; SetStatusText("Connection received."); SetTitle("CONNECTION RECEIVED"); } } } } IMPLEMENT_APP(MyApp) These are the errors I am now getting:
Severity Code Description Project File Line Suppression State Error (active) E0289 no instance of constructor "wxSocketServer::wxSocketServer" matches the argument list VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 50 Severity Code Description Project File Line Suppression State Error (active) E0349 no operator "=" matches these operands VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 62 Severity Code Description Project File Line Suppression State Error (active) E0289 no instance of constructor "wxSocketServer::wxSocketServer" matches the argument list VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 62 Severity Code Description Project File Line Suppression State Error C2665 'wxSocketServer::wxSocketServer': no overloaded function could convert all the argument types VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 50 Severity Code Description Project File Line Suppression State Error C2665 'wxSocketServer::wxSocketServer': no overloaded function could convert all the argument types VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 62 Severity Code Description Project File Line Suppression State Error C2679 binary '=': no operator found which takes a right-hand operand of type 'wxSocketServer *' (or there is no acceptable conversion) VNC_GUI_MAIN C:\Users\User\source\repos\VNC_GUI_MAIN\main.cpp 62
Initialize without specifying flagsWhat about the first parameter address? A complete error message would contain an answer.