//=====================================================================================
bool Client::Connect( const wxIPV4address& address )
{
	wxSocketClient* socketClient = new wxSocketClient( wxSOCKET_NOWAIT );
	socket = new Socket( socketClient );

	// Try once before throwing up the progress dialog.
	socketClient->Connect( address, false );
	if( socketClient->WaitOnConnect( 1, 0 ) && socketClient->IsConnected() )
		return true;
	
	wxString hostName = address.Hostname();
	int tryCount = 0;
	int maxTries = 10;
	wxString progressMessage = wxT( "Connecting..." );
	wxGenericProgressDialog progressDialog( wxT( "Connecting to host: " ) + hostName, progressMessage, maxTries, wxGetApp().GetFrame(), wxPD_APP_MODAL | wxPD_CAN_ABORT );
	while( tryCount < maxTries )
	{
		socketClient->Connect( address, false );
		if( socketClient->WaitOnConnect( 1, 0 ) && socketClient->IsConnected() )
			return true;

		tryCount++;
		if( tryCount == maxTries )
			progressMessage = wxT( "Connection attempt failed!" );

		bool cancel = !progressDialog.Update( tryCount, progressMessage );
		if( cancel )
			break;
	}

	return false;
}
示例#2
0
void Pinger::newPingResultNoLockHelper(const wxIPV4address& ip, long duration) {
	wxString theip = ip.IPAddress();
	wxLogDebug(_T("PING for %s is %ld"), theip.c_str(), duration);

	if(this->addresslist.find(theip) != this->addresslist.end()) {
		wxLogDebug(_T(" Found %d servers"), this->addresslist[theip].second.size());
		for(serverlist_t::iterator i = this->addresslist[theip].second.begin(); i != this->addresslist[theip].second.end(); ++i) {
			this->updateAttribute(*i, this->lblping, Attribute<uint16_t>(duration));
		}
	}
	else {
		wxLogDebug(_T("Response for a ping we don't care about?"));
	}
}
示例#3
0
wxString
CreateIdent(const wxIPV4address& addr)
{
    return wxString::Format(wxT("%s:%d"),addr.IPAddress().c_str(),addr.Service());
}