I'm triyng to do socket server follow the example at the wxWidgets book (code bellow), but when I build the app same errors are show. I'm using VS2005 + PSDK + wxWidgets 2.6.3
main.h
Code: Select all
#ifndef INCLUDED_SOCKETAPP_H
#define INCLUDED_SOCKETAPP_H
class MyFrame: public wxFrame
{
public:
MyFrame( const wxString& title );
void OnServerStart( wxCommandEvent& event );
void OnServerEvent(wxSocketEvent& event );
void OnSocketEvent(wxSocketEvent& event);
wxSocketServer* m_server;
DECLARE_EVENT_TABLE()
};
class MyApp: public wxApp
{
bool OnInit();
};
#endif
Code: Select all
#include "wx/wx.h"
#include "wx/socket.h"
#include "main.h"
enum
{
SERVER_START = 100,
SERVER_STOP,
SERVER_ID,
SOCKET_ID
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(SERVER_START, MyFrame::OnServerStart)
EVT_SOCKET(SERVER_ID, MyFrame::OnServerEvent)
EVT_SOCKET(SOCKET_ID, MyFrame::OnSocketEvent)
END_EVENT_TABLE()
MyFrame::MyFrame ( const wxString& title ): wxFrame(NULL, wxID_ANY, title)
{
// Criando a barra de menus - menuBar
wxMenuBar *menuBar = new wxMenuBar;
// Criando o primeiro item de menu - menuFile
wxMenu *menuServer = new wxMenu;
menuBar->Append( menuServer , "&Server" );
menuServer->Append( SERVER_START , "&Start" , "Start Server" );
menuServer->Append( SERVER_STOP , "&Stop" , "Stop Server" );
//menuServer->Append( wxID_SAVE , "&Save...\tCtrl+S" , "Open account" );
//menuServer->Append( wxID_CLOSE , "&Close\tCtrl+F4" , "Close this account" );
// Anexando o menuBar criado ao MenuBar do frame
SetMenuBar( menuBar );
}
void MyFrame::OnServerStart(wxCommandEvent& WXUNUSED(event))
{
// Create the address - defaults to localhost:0 initially
wxIPV4address addr;
addr.Service(3000);
// Create the socket. We maintain a class pointer so we can
// shut it down
m_server = new wxSocketServer(addr);
// We use Ok() here to see if the server is really listening
if (! m_server->Ok())
{
return;
}
// Set up the event handler and subscribe to connection events
m_server->SetEventHandler(*this, SERVER_ID);
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
m_server->Notify(true);
}
void MyFrame::OnServerEvent(wxSocketEvent& WXUNUSED(event))
{
// Accept the new connection and get the socket pointer
wxSocketBase* sock = m_server->Accept(false);
// Tell the new socket how and where to process its events
sock->SetEventHandler(*this, SOCKET_ID);
sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
sock->Notify(true);
}
void MyFrame::OnSocketEvent(wxSocketEvent& event)
{
wxSocketBase *sock = event.GetSocket();
// Process the event
switch(event.GetSocketEvent())
{
case wxSOCKET_INPUT:
{
char buf[10];
// Read the data
sock->Read(buf, sizeof(buf));
// Write it back
sock->Write(buf, sizeof(buf));
// We are done with the socket, destroy it
sock->Destroy();
break;
}
case wxSOCKET_LOST:
{
sock->Destroy();
break;
}
}
}
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( "Socket Application" );
frame->CreateStatusBar();
frame->SetStatusText("Socket");
frame->Show(TRUE);
SetTopWindow(frame);
return true;
}
------ Build started: Project: socket, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
wxbase26d_net.lib(sckaddr.obj) : error LNK2019: unresolved external symbol "public: void __thiscall wxStringData::Free(void)" (?Free@wxStringData@@QAEXXZ) referenced in function "public: void __thiscall wxStringData::Unlock(void)" (?Unlock@wxStringData@@QAEXXZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
Debug/socket.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Marcelo Magalh