add tests for GetLocal() and GetPeer() (see #10779)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -31,6 +31,14 @@
|
|||||||
|
|
||||||
#include "wx/socket.h"
|
#include "wx/socket.h"
|
||||||
|
|
||||||
|
// this example is currently written to use only IP or only IPv6 sockets, it
|
||||||
|
// should be extended to allow using either in the future
|
||||||
|
#if wxUSE_IPV6
|
||||||
|
typedef wxIPV6address IPaddress;
|
||||||
|
#else
|
||||||
|
typedef wxIPV4address IPaddress;
|
||||||
|
#endif
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// resources
|
// resources
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -190,13 +198,11 @@ MyFrame::MyFrame() : wxFrame((wxFrame *)NULL, wxID_ANY,
|
|||||||
delete wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
|
delete wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
|
||||||
|
|
||||||
// Create the address - defaults to localhost:0 initially
|
// Create the address - defaults to localhost:0 initially
|
||||||
#if wxUSE_IPV6
|
IPaddress addr;
|
||||||
wxIPV6address addr;
|
|
||||||
#else
|
|
||||||
wxIPV4address addr;
|
|
||||||
#endif
|
|
||||||
addr.Service(3000);
|
addr.Service(3000);
|
||||||
|
|
||||||
|
wxLogMessage("Creating server at %s:%u", addr.IPAddress(), addr.Service());
|
||||||
|
|
||||||
// Create the socket
|
// Create the socket
|
||||||
m_server = new wxSocketServer(addr);
|
m_server = new wxSocketServer(addr);
|
||||||
|
|
||||||
@@ -206,10 +212,13 @@ MyFrame::MyFrame() : wxFrame((wxFrame *)NULL, wxID_ANY,
|
|||||||
wxLogMessage("Could not listen at the specified port !");
|
wxLogMessage("Could not listen at the specified port !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPaddress addrReal;
|
||||||
|
if ( !m_server->GetLocal(addrReal) )
|
||||||
|
wxLogMessage("ERROR: couldn't get the address we bound to");
|
||||||
else
|
else
|
||||||
{
|
wxLogMessage("Server listening at %s:%u",
|
||||||
wxLogMessage("Server listening.");
|
addrReal.IPAddress(), addrReal.Service());
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the event handler and subscribe to connection events
|
// Setup the event handler and subscribe to connection events
|
||||||
m_server->SetEventHandler(*this, SERVER_ID);
|
m_server->SetEventHandler(*this, SERVER_ID);
|
||||||
@@ -335,7 +344,12 @@ void MyFrame::OnServerEvent(wxSocketEvent& event)
|
|||||||
|
|
||||||
if (sock)
|
if (sock)
|
||||||
{
|
{
|
||||||
wxLogMessage("New client connection accepted");
|
IPaddress addr;
|
||||||
|
if ( !sock->GetPeer(addr) )
|
||||||
|
wxLogMessage("New connection from unknown client accepted.");
|
||||||
|
else
|
||||||
|
wxLogMessage("New client connection from %s:%u accepted",
|
||||||
|
addr.IPAddress(), addr.Service());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user