-2

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 
4
  • 1
    That is not a error message. Please post a complete error message from the Build panel. Commented Sep 18, 2023 at 15:04
  • Can we re-open. I was about to answer the question? Commented Sep 18, 2023 at 15:10
  • Initialize without specifying flags What about the first parameter address? A complete error message would contain an answer. Commented Sep 18, 2023 at 15:12
  • @MarianneSanders, please check the socket (server) sample. Commented Sep 18, 2023 at 15:23

1 Answer 1

-1

Here's a hint to what's wrong? What port is your server listening on? Where in the code is that specified?

You are initializing wxSocketServer like this:

m_server(), // Initialize without specifying flags 

A quick internet search reveals it has this as a constructor:

wxSocketServer (const wxSockAddress &address, wxSocketFlags flags=wxSOCKET_NONE) 

So you got to specify a listening address that includes a port.

Maybe this is what you want:

  • Declare m_server as a pointer
  • Initialize it manually in your constructor like this:
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); 

I think the bigger question is why you need to construct a server object when your stated purpose is to make a VNC client. Unless the VNC protocol requires clients to accept connections back, this might not be needed.

Sign up to request clarification or add additional context in comments.

8 Comments

Declare m_server as a pointer is a very bad advice after C++98. Neither pointer nor addr variable are necessary.
wxIPV4address::Server doesn't exist.
@273K - I meant "Service".
I am programming the GUI right now, I want the GUI to constantly be looking to a web server for the data being sent by the computer transmitting it's screen, and I need to be able to send data about key input to the computer I am connecting to so that I can control it. Do I not need to create a server object to do this?
I want the GUI to constantly be looking -- Admittedly, I have never used Qt, but the GUI shouldn't be doing business logic except to retrieve input and display output. If you are programming key business logic inside a GUI component, what happens if you decide to change the GUI? Do you now have to change the business logic?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.