本文整理汇总了C++中NetAddress类的典型用法代码示例。如果您正苦于以下问题:C++ NetAddress类的具体用法?C++ NetAddress怎么用?C++ NetAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
//-----------------------------------------------------------------------------
bool TCPSocket::connect(const NetAddress& destination)
{
int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sd <= 0)
{
os::printf("Failed to open socket\n");
m_socket = 0;
return false;
}
m_socket = sd;
sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(destination.address());
address.sin_port = htons(destination.port());
if (::connect(sd, (const sockaddr*)&address, sizeof(sockaddr_in)) < 0)
{
os::printf("Failed to connect socket\n");
close();
return false;
}
return true;
}
示例2: addressToPTB
static shared_ptr<PixelTransferBuffer> addressToPTB(const NetAddress& addr) {
std::string str = std::string("HTTP://") + addr.ipString() + ":" + format("%d", addr.port());
debugAssert(str.size() <= 28);
QRcode* qrcode = encode(str.c_str(), (int)str.size());
const int N = qrcode->width;
shared_ptr<PixelTransferBuffer> buffer = CPUPixelTransferBuffer::create(N, N, ImageFormat::L8());
unorm8* dst = reinterpret_cast<unorm8*>(buffer->mapWrite());
const unsigned char* src = qrcode->data;
const unorm8 BLACK = unorm8::fromBits(0x00);
const unorm8 WHITE = unorm8::fromBits(0xFF);
for (int i = 0; i < N * N; ++i) {
// The bytes are in the opposite convention
dst[i] = (src[i] & 1) ? BLACK : WHITE;
}
dst = NULL;
buffer->unmap();
QRcode_free(qrcode);
return buffer;
}
示例3: sendData
int TSocket::sendData( char const* data , size_t num , char const* addrName , unsigned port )
{
NetAddress addr;
if ( !addr.setInternet( addrName , port ) )
return false;
return sendData( data , num , addr );
}
示例4: assert
bool TSocket::connect( char const* addrName , unsigned port )
{
assert( mSocketObj == INVALID_SOCKET );
NetAddress addr;
if ( !addr.setInternet( addrName , port ) )
return false;
return connect( addr );
}
示例5: onConnected
void Robot::onConnected(Link *link, const NetAddress& localAddr, const NetAddress& peerAddr)
{
static int g_connectedRobotCnt = 0;
++g_connectedRobotCnt;
m_link = link;
if (g_connectedRobotCnt % 100 == 0) {
LOG_INFO << name() << " <" << localAddr.toIpPort() << "> connect to <" << peerAddr.toIpPort() << "> success, current robot cnt = " << m_robotMgr->m_robotMap.size();
}
// m_link->send("1\r\n");
}
示例6: while
int NetSocket::DispatchIncoming()
{
int length = 0;
int count = 0;
NetAddress from;
while ((length = ReceivePacketIntern(&from)))
{
if (length == -1)
break;
INetChannel *channel = (INetChannel *)m_Channels.GetFirst();
while (channel)
{
if (from.Equal(channel->GetTargetAddress())) {
channel->ProcessIncoming(m_Buffer, length);
break;
}
channel = (INetChannel *)m_Channels.GetNext();
}
// not found an existing channel for this address.
// create a new channel
if (!channel)
{
// do accept only connectionless (\xFF\xFF\xFF\xFF) incoming packet.
if (*(int *)m_Buffer == CONNECTIONLESS_HEADER)
{
NetPacket *p = new NetPacket;
p->time = m_System->GetTime();
p->address.FromNetAddress(&from);
p->connectionless = true;
p->seqnr = -1;
// cut connectionless data
p->data.Resize(length - 4);
p->data.WriteBuf(&m_Buffer[4], length - 4);
p->data.Reset();
m_IncomingPackets.AddHead(p);
}
}
count++;
}
return count;
}
示例7: connect
int connect(socket_t sockfd, NetAddress &peerAddr)
{
const struct sockaddr_in &addr = peerAddr.getSockAddr();
int ret = ::connect(sockfd, (struct sockaddr *)&addr, static_cast<socklen_t>(sizeof addr));
return ret;
}
示例8: DYNAMIC_ASSERT
//-----------------------------------------------------------------------------
void ServerNetApplyManager::onRecvServerConncectLogin( I32 id, Char16* name, GameNetType type, U64 serverUniqueFlag, U32 serverId,U32 code ,Char8* serverVersion)
{
// 服务器版本验证
if (StrCmp(serverVersion,SERVER_VERSION_NUMBER))
{
Char8 desc[256] = {0};
//服务器版本不一致
SServerSetting& setting = SServerSetting::getInstance();
CoreInfo* coreInfo = setting.getCoreInfo();
if (!coreInfo)
{
DYNAMIC_ASSERT(false);
}
MGStrOp::sprintf(desc,256,"版本验证错误,当前程序版本为%s,对方版本为%s",serverVersion,SERVER_VERSION_NUMBER);
LoginNetPacketProcesser::getInstance().sendLoginVersionErrorInfo(id,(Char16*)coreInfo->name.c_str(),(Byte)coreInfo->type,desc,StrLen(desc));
MGStrOp::sprintf(desc,256,"版本验证错误,当前程序版本为%s,对方版本为%s",SERVER_VERSION_NUMBER,serverVersion);
MG::MsgBox::show(desc,"版本验证");
return;
}
IServerDllInterface* serverInterface = ServerMain::getInstance().getServerDllInterface();
if (!ServerMain::getInstance().addServer(serverId,id))
{
//ServerMain::getInstance().closeServer(id);
//DYNAMIC_ASSERT(false);
//Char16 temp[256] = {0};
//MGStrOp::sprintf(temp,256,L"有重复的服务器id,请检查%s的ServerConfig.txt文件!",name);
//MG::MsgBox::show(temp,L"配置错误");
return;
}
NetAddress address = getAddress( getServerHandle(), id );
setConnectServerLoginState(address.getUin(),id,true,true);
//MG_LOG(out_error,"onLogin %s %d \n",address.getIPStr(),address.getPort());
Sleep(5);
serverInterface->onServerConnected( id, type, serverId, serverUniqueFlag, &address );
I32 len = WStrLen(name);
Char16* postName = MG_NEW Char16[MAX_SERVER_NAME_LEN];
WStrnCpyS(postName,MAX_SERVER_NAME_LEN,name,len);
NetAddress* postAddr = new NetAddress(address);
::PostMessage(ServerMain::getInstance().getDialogHandle(),LAUNCH_SERVER_CONNECT,(WPARAM)postName,(LPARAM)postAddr);
}
示例9: connect
bool TSocket::connect( NetAddress const& addr )
{
if ( !createTCP( true ) )
{
return false;
}
int result = ::connect( getSocketObject() , (sockaddr*)&addr.get() , sizeof( addr.get() ) );
if ( result == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK )
{
socketError("Failed connect()");
return false;
}
mState = SKS_CONNECTING;
return true;
}
示例10: bindAddress
bool bindAddress(socket_t sockfd, const NetAddress& localaddr)
{
int ret = bind(sockfd, (struct sockaddr *)&localaddr.m_addr, sizeof(localaddr.m_addr));
if(ret == SOCKET_ERROR) {
LOG_SYSTEM_ERR << "bindAddress failed address=<" << localaddr.toIpPort() << ">";
return false;
}
return true;
}
示例11: processURL
Boolean SIPClient::processURL(char const* url) {
do {
// If we don't already have a server address/port, then
// get these by parsing the URL:
if (fServerAddress.s_addr == 0) {
NetAddress destAddress;
if (!parseSIPURL(envir(), url, destAddress, fServerPortNum)) break;
fServerAddress.s_addr = *(unsigned*)(destAddress.data());
if (fOurSocket != NULL) {
fOurSocket->changeDestinationParameters(fServerAddress,
fServerPortNum, 255);
}
}
return True;
} while (0);
return False;
}
示例12: getSDPDescriptionFromURL
char* getSDPDescriptionFromURL(Medium* client, char const* url,
char const* username, char const* password,
char const* proxyServerName,
unsigned short proxyServerPortNum,
unsigned short clientStartPortNum) {
SIPClient* sipClient = (SIPClient*)client;
if (proxyServerName != NULL) {
// Tell the SIP client about the proxy:
NetAddressList addresses(proxyServerName);
if (addresses.numAddresses() == 0) {
client->envir() << "Failed to find network address for \""
<< proxyServerName << "\"\n";
} else {
NetAddress address = *(addresses.firstAddress());
unsigned proxyServerAddress // later, allow for IPv6 #####
= *(unsigned*)(address.data());
if (proxyServerPortNum == 0) proxyServerPortNum = 5060; // default
sipClient->setProxyServer(proxyServerAddress, proxyServerPortNum);
}
}
if (clientStartPortNum == 0) clientStartPortNum = 8000; // default
sipClient->setClientStartPortNum(clientStartPortNum);
char* result;
if (username != NULL && password != NULL) {
result = sipClient->inviteWithPassword(url, username, password);
} else {
result = sipClient->invite(url);
}
extern unsigned statusCode;
statusCode = sipClient->inviteStatus();
return result;
}
示例13: AllocAddressesForHost
void AllocAddressesForHost(NetAddresses& addressesToAllocTo, std::string& host_name, const std::string& service){
addrinfo hints;
addrinfo* addr;
if (host_name == ""){
host_name = "local_host";
}
//which network layer it's using
memset(&hints, 0, sizeof(hints)); //sets all hints to 0
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM; // stream based, determines transport layer TCP
hints.ai_flags = AI_PASSIVE; // used for binding/listening
int status = getaddrinfo(host_name.c_str(), service.c_str(), &hints, &addr);
if (status != 0) {
//printf("Failed to create socket address! %s\n", gai_strerror(status));
}
addrinfo *iter;
for (iter = addr; iter != nullptr; iter = iter->ai_next) {
GetInAddress(iter->ai_addr);
//instantiate address
NetAddress newOutAddress;
newOutAddress.Init(iter->ai_addr, iter->ai_addrlen);
addressesToAllocTo.push_back(newOutAddress);
}
freeaddrinfo(addr);
}
示例14: getSDPDescription
void getSDPDescription(RTSPClient::responseHandler* afterFunc) {
extern char* proxyServerName;
if (proxyServerName != NULL) {
// Tell the SIP client about the proxy:
NetAddressList addresses(proxyServerName);
if (addresses.numAddresses() == 0) {
ourSIPClient->envir() << "Failed to find network address for \"" << proxyServerName << "\"\n";
} else {
NetAddress address = *(addresses.firstAddress());
unsigned proxyServerAddress // later, allow for IPv6 #####
= *(unsigned*)(address.data());
extern unsigned short proxyServerPortNum;
if (proxyServerPortNum == 0) proxyServerPortNum = 5060; // default
ourSIPClient->setProxyServer(proxyServerAddress, proxyServerPortNum);
}
}
extern unsigned short desiredPortNum;
unsigned short clientStartPortNum = desiredPortNum;
if (clientStartPortNum == 0) clientStartPortNum = 8000; // default
ourSIPClient->setClientStartPortNum(clientStartPortNum);
extern char const* streamURL;
char const* username = ourAuthenticator == NULL ? NULL : ourAuthenticator->username();
char const* password = ourAuthenticator == NULL ? NULL : ourAuthenticator->password();
char* result;
if (username != NULL && password != NULL) {
result = ourSIPClient->inviteWithPassword(streamURL, username, password);
} else {
result = ourSIPClient->invite(streamURL);
}
int resultCode = result == NULL ? -1 : 0;
afterFunc(NULL, resultCode, strDup(result));
}
示例15: onDisconnect
void Robot::onDisconnect(Link *link, const NetAddress& localAddr, const NetAddress& peerAddr)
{
/*
if (link->m_isCreateByConnector) {
Robot *robot = m_robotMgr->createRobot();
m_robotMgr->m_wan.connect(peerAddr.toIp(), peerAddr.toPort(), *robot);
}
*/
if (m_robotMgr->m_robotMap.size() - 1 % 100 >= 0) {
LOG_INFO << "robot<" << m_robotId << "> <" << localAddr.toIpPort() << "> to gateserver <" << peerAddr.toIpPort() << "> closed! current robot cnt = " << m_robotMgr->m_robotMap.size() - 1;
}
m_robotMgr->onRobotDisconnect(this);
}