当前位置: 首页>>代码示例>>C++>>正文


C++ TInetAddr::SetPort方法代码示例

本文整理汇总了C++中TInetAddr::SetPort方法的典型用法代码示例。如果您正苦于以下问题:C++ TInetAddr::SetPort方法的具体用法?C++ TInetAddr::SetPort怎么用?C++ TInetAddr::SetPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TInetAddr的用法示例。


在下文中一共展示了TInetAddr::SetPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestStepResult

enum TVerdict CEsockTest2_4::easyTestStepL()
	{
	TESTL(EPass == TestStepResult());
	// double bind on different sockets
	
	// get IP address
	TInetAddr addr;
	TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.4")), _L("ipAddress"), addr));
	
	// set port number to a valid value
	addr.SetPort(9);
	
	// socket already opened - retrieve
	// socket handle and bind
	TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr);
	
	// bind should succeed
	TESTEL(nRet == KErrNone, nRet);
	
	// socket already opened - retrieve
	// socket handle and bind again to same address
	nRet = iEsockSuite->GetSocketHandle(2).Bind(addr);
	
	// second bind should fail
	TESTEL(nRet == KErrInUse, nRet);
	
	return EPass;
	}
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:28,代码来源:EsockTestSection2.cpp

示例2: ILibSocketWrapper_joinmulticastgroup

int ILibSocketWrapper_joinmulticastgroup(int socketObject, long multicastAddress, long multicastInterface)
{
	RSocket *s = (RSocket*)SocketArray[socketObject];

	int RetVal;
	TInetAddr dst;
	
	dst.SetAddress(htonl(multicastAddress));
	dst.SetPort(0);
	dst.ConvertToV4Mapped();
	
	TPckgBuf<TIp6Mreq> req;
	
	req().iAddr = dst.Ip6Address();
	req().iInterface = ILibSocketWrapper_GetInterfaceIndex(multicastInterface);
   	RetVal = s->SetOpt(KSoIp6JoinGroup,KSolInetIp,req);
	if(RetVal==KErrNone)
	{
		return(0);
	}
	else
	{
		s->SetOpt(KSoIp6LeaveGroup,KSolInetIp,req);
		return(-1);
	}
}
开发者ID:GufCab,项目名称:Semester-Projekt---Test-Kode,代码行数:26,代码来源:ILibSocketWrapper.cpp

示例3: ConstructL

void CSender::ConstructL()
	{
	// Connect to socket server
	User::LeaveIfError(iSocketServ.Connect());
	User::LeaveIfError(iSocketServ.ShareAuto());  // allow other threads to use
	
	
	iSendSocket.Close();
	User::LeaveIfError(iSendSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp));
	
	TRequestStatus status;

	// Request the Socket to connect to the destination address (implicit Connection)
	TInetAddr destAddr;
	destAddr.Input(KRemoteAddr);
	destAddr.SetPort(KRemotePort);
	iSendSocket.Connect(destAddr, status);
	
	RDEBUGPRINTLOGGER1(_L("RPS: Waiting for Send socket to connect to remote destination ..."));
	User::WaitForRequest(status);
	RDEBUGPRINTLOGGER2(_L("RPS: Wait over. Status returned: %d\n"), status.Int());
	
	if(status != KErrNone)
		{
		RDEBUGPRINTLOGGER1(_L("RPS: Socket could not Connect!!"));
		User::Leave(KErrCouldNotConnect);
		}
	else
		{
		RDEBUGPRINTLOGGER1(_L("RPS: Send socket connected to remote destination "));
		}
	}
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:32,代码来源:Sender.cpp

示例4: StartL

TBool CTcpTestConsole::StartL()
	{
	TLex args(iChars);
	// args are separated by spaces
	args.SkipSpace(); 
	
	TInetAddr addr;
	TInt size;

	if(!iMode)
		{
		//Get ip addr
		TPtrC cmdAddr = args.NextToken();
		if(!args.Eos())
			{
			if(KErrNone == addr.Input(cmdAddr))
				{
				args.Inc();
				}
			else
				{
				return EFalse;
				}
			}
		else
			{
			return EFalse;
			}
		}
	
	//Get port
	TInt port;
	if(KErrNone != args.Val(port))
		{
		return EFalse;
		}
	addr.SetPort(port);

	//Get pkg size
	args.Inc();
	if(KErrNone != args.Val(size))
		{
		return EFalse;
		}
	
	iCommandMode = ECommandRunning;
    if (iIsTcp)
        {
        iConsole->Printf(_L("Test for TCP...\n"));
        iTcp = CTcpProcess::NewL(*iConsole, addr, port, size, iMode);
        }
    else
        {
        iConsole->Printf(_L("Test for UDP...\n"));
        iUdp = CUdpProcess::NewL(*iConsole, addr, port, size, iMode);
        }
		
	return ETrue;

	}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:60,代码来源:tcptest.cpp

示例5:

enum TVerdict CEsockTest11_1::easyTestStepL()
	{
	// get ip address to connect to
	TInetAddr addr;
	TESTL(GetIpAddressFromConfig(_L("Test_Common"), _L("ipAddress"), addr));
	
	// get port number to connect to
	TInt port;
	TESTL(GetIntFromConfig(_L("Test_11.1"), _L("port"), port));
	
	// set remote address port
	addr.SetPort(port);
	
	// open a TCP socket
	RSocket sock;
	CleanupClosePushL(sock);
	TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
	TESTEL(KErrNone == nRet, nRet);
	
	// connect to the remote address
	TRequestStatus stat;
	sock.Connect(addr, stat);
	User::WaitForRequest(stat);
	TESTEL(stat==KErrNone, stat.Int());
	
	// get the remote name of the connected socket
	TInetAddr addr1;
	sock.RemoteName(addr1);
	
	// check this matches the address we connected to
	TESTL(addr.CmpAddr(addr1));
	
	CleanupStack::PopAndDestroy(1, &sock);
	return EPass;
	}
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:35,代码来源:EsockTestSection11.cpp

示例6: parser

int
TcpipComm::Open(CConsoleBase *cons, TDes &name, TDesC &destination,
			TRequestStatus &st)
{
  int r;
  TInetAddr addr;
  TPtrC servername;
  int port = 0;

  if((r = iServ.Connect()) != KErrNone)
    return r;
  if((r = iSock.Open(iServ,KAfInet,KSockStream,KProtocolInetTcp)) != KErrNone)
    return r;


  //////////////
  // Parse the destination, which is of the form ip.adress:port
  for(r = 0; r < destination.Length(); r++)
    if(destination[r] == ':')
      break;
  servername.Set(destination.Left(r)); // Wont include ':'
  TLex parser(destination.Mid(r+1));
  parser.Val(port);

  addr.SetPort(port);
  if(addr.Input(servername) != KErrNone) // Its a real hostname, wont resolv
    return 1;

  iSock.Connect(addr, st);

  TPckgBuf<int> one(1);
  iSock.SetOpt(KSoTcpNoDelay, KSolInetTcp, one);

  return 0;
}
开发者ID:BackupTheBerlios,项目名称:p3nfs-svn,代码行数:35,代码来源:tcpip.cpp

示例7: net_if_getaddr4

/**
 * Get the local IP address of the device
 *
 * @note Requires at least one IP packet sent in advance!
 */
int net_if_getaddr4(const char *ifname, int af, struct sa *ip)
{
	(void)ifname;

	if (AF_INET != af)
		return EAFNOSUPPORT;

	/* Already cached? */
	if (sa_isset(&local_ip, SA_ADDR)) {
		sa_cpy(ip, &local_ip);
		return 0;
	}

	RSocketServ ss;
	RSocket s;
	TInt ret;

	ret = ss.Connect();
	if (KErrNone != ret) {
		DEBUG_WARNING("connecting to socket server fail (ret=%d)\n",
			      ret);
		return ECONNREFUSED;
	}

	ret = s.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp);
	if (KErrNone != ret) {
		DEBUG_WARNING("open socket failed (ret=%d)\n", ret);
		return ECONNREFUSED;
	}

	TInetAddr bind;
	bind.SetPort(0);
	bind.SetAddress(KInetAddrAny);

	ret = s.Bind(bind);
	if (KErrNone != ret) {
		DEBUG_WARNING("bind socket failed (ret=%d)\n", ret);
		return ECONNREFUSED;
	}

	TInetAddr local;
	s.LocalName(local);

	s.Close();
	ss.Close();

	sa_set_in(&local_ip, local.Address(), local.Port());

	DEBUG_NOTICE("local IP addr: %j\n", &local_ip);

	if (!sa_isset(&local_ip, SA_ADDR))
		return EINVAL;

	sa_cpy(ip, &local_ip);

	return 0;
}
开发者ID:ClearwaterCore,项目名称:libre-upstream,代码行数:62,代码来源:snet.cpp

示例8: Connect

void HXSymbianTCPConnector::Connect(RSocket& socket,
				    ULONG32 ulAddr, UINT16 nPort)
{
    m_addr.SetAddress(ulAddr);
    m_addr.SetPort(nPort);

    iStatus = KRequestPending;
    socket.Connect(m_addr, iStatus);
    SetActive();
}
开发者ID:muromec,项目名称:qtopia-ezx,代码行数:10,代码来源:hxsymbiantcpsock.cpp

示例9: Listen

void CMSocketS::Listen()
{
    
    if (m_status != IDLE)
    {
        m_pNotify->OnAccept(MERN_INITIALIZE, NULL);
        return;        
    }
    CMNetConnMgr& mgr = CMNetConnMgr::Instance();

    //网络未接入直接返回失败
    if (mgr.CurrentType() == CMNetConnMgr::NONE)
    {
        //
        m_pNotify->OnAccept(MERN_INITIALIZE, NULL);
    }
    
    //构造本地侦听ip,端口
    RHostResolver hostResolver;
    TNameEntry entry;
    TInetAddr aAddress;
    User::LeaveIfError( hostResolver.Open( mgr.SocketServer(), KAfInet, 
                                          KProtocolInetTcp, mgr.Connection() ));
    CleanupClosePushL( hostResolver );
 
    User::LeaveIfError(hostResolver.GetByName(TPtrC(), entry));
    if (!TInetAddr::Cast(entry().iAddr).IsWildAddr())
    {
        aAddress = TInetAddr::Cast(entry().iAddr);
    }
     CleanupStack::PopAndDestroy(); // hostResolver
     aAddress.SetPort(m_nPort);
     
     
     //开始侦听
     User::LeaveIfError( m_sk.Open( 
             mgr.SocketServer(), KAfInet, KSockStream, KProtocolInetTcp ) );
     User::LeaveIfError( m_sk.Bind( aAddress ) );
     
     User::LeaveIfError( m_sk.Listen( 1 ) );

     CMSocketC* pSocketC = new CMSocketC(NULL);
//     pSocketC->m_status = CMSocketC::CONNECTED;    
 //    if (pSocketC == NULL || pSocketC->GetStatus() != CMSocketC::NOTCONNECTED)
 //    {
 //        m_pNotify->OnAccept(MERN_WRONG_PARAM, NULL);
 //        return;
 //    }
     User::LeaveIfError( pSocketC->m_sk.Open( mgr.SocketServer() ) );
     m_sk.Accept( pSocketC->m_sk, iStatus );    
     m_status = LISTENING;
     m_pSocketC = pSocketC;
     SetActive();
     
}
开发者ID:jianbinking,项目名称:mlplayer_midea,代码行数:55,代码来源:cmsocketc_sym.cpp

示例10:

enum TVerdict CEsockTest17_7::easyTestStepL()
	{
	//
	//     IsWildPort() //
	//
	
	TInetAddr addr;
	
	addr.SetAddress(IPADDR(126,0,0,1));
	addr.SetPort(0);		// IP Address to 126,0,0,1 and Port to Zero
	TESTL(addr.IsWildPort()!=EFalse);				// Port = 0 -	True
	
	addr.SetPort(21);								// Sets Port to 21 FTP
	TESTL(addr.IsWildPort()==EFalse);				// Port = 21 -	False
	
	addr.SetAddress(IPADDR(191,220,145,22));		// IP Address to 191.220.145.22
	TESTL(addr.IsWildPort()==EFalse);				// Port = 21 -	False
	
	addr.SetPort(0);								// Sets Port to 0
	TESTL(addr.IsWildPort()!=EFalse);				// Port = 0 -	True
	
	return EPass;
	}
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:23,代码来源:EsockTestSection17.cpp

示例11:

void TFtpTest02Params::SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName,
		const TDesC8& aUserName, const TDesC8& aPassword, const TDesC8& aDirectoryPath,
		const TDesC8& aRemoteFileName, const TDesC& aLocalFileName)
	{
	iInetAddr.Input(aInetAddr);
	iInetAddr.SetPort(aPort);
	iPort=aPort;
	iHostName=aHostName;
	iUserName.Set(aUserName);
	iDirectoryPath.Set(aDirectoryPath);
	iPassword.Set(aPassword);
	iRemoteFileName.Set(aRemoteFileName);
	iLocalFileName.Set(aLocalFileName);
	}
开发者ID:kuailexs,项目名称:symbiandump-mw2,代码行数:14,代码来源:FTPTST02.CPP

示例12: SocketOpen

SOAP_SOCKET CAafSocketUtils::SocketOpen(struct soap *soap, const char *endpoint, const char *host, int port)
{
	__LOGSTR_TOFILE("CAafSocketUtils::SocketOpen() begins");

	// Set endpoint
	if (endpoint)
		strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)-1);

	// Get thread entry point data
	MGSoapData* entryPointData = reinterpret_cast<MGSoapData*>(soap->user);

	// Open socket
	entryPointData->GetSocketInstance()->Open(*entryPointData->GetConnectionManager()->GetSocketServ(), KAfInet, KSockStream, KProtocolInetTcp, *entryPointData->GetConnectionManager()->GetConnection());

	RHostResolver hostResolver;

	// Open resolver socket
	User::LeaveIfError(hostResolver.Open(*entryPointData->GetConnectionManager()->GetSocketServ(), KAfInet, KProtocolInetTcp)) ;

	TNameEntry hostAddress;
	TRequestStatus status;

	HBufC* serverName = CAafUtils::StringToDescriptorLC(host);

	// Attempt to resolve name
	hostResolver.GetByName(*serverName, hostAddress, status); 

	CleanupStack::PopAndDestroy(serverName);

	User::WaitForRequest(status);

	// Connect to the specified host
	TInetAddr addrOnPort;

	addrOnPort = hostAddress().iAddr;
	addrOnPort.SetPort((TUint)port);

	entryPointData->GetSocketInstance()->Connect(addrOnPort, status);

	User::WaitForRequest(status);

	__LOGSTR_TOFILE("CAafSocketUtils::SocketOpen() ends");

	if (status.Int() == KErrNone)
		return SOAP_OK;

	return SOAP_ERR;
}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:48,代码来源:Aafsocketutils.cpp

示例13: ConnectL

void CTrkSocketCommPort::ConnectL()
{
	TInetAddr address;
	TInt err = KErrNone;
	
//	address.SetPort(10000);
//	err = address.Input(_L("10.86.2.93"));
//
//	TRequestStatus stat;
//	iSocket.Connect(address, stat);
//	User::WaitForRequest(stat);

//	iConnected = ETrue;

//	TSockAddr test;
//	iSocket.LocalName(test);
//	TUint lp = iSocket.LocalPort();

	
	address.SetPort(6110);
	err = address.Input(_L("127.0.0.1"));
//	err = address.Input(_L("0.0.0.0"));

	err = iSocket.Bind(address);
	if (err != KErrNone)
	{
		User::Leave(err);
	}

	err = iSocket.Listen(1);
	if (err != KErrNone)
	{
		User::Leave(err);
	}

	RSocket blankSocket;
	err = blankSocket.Open(iSocketServ);

	TRequestStatus stat;
	iSocket.Accept(blankSocket, stat);
//	SetActive();
	User::WaitForRequest(stat);
	User::Leave(5000);

//	iSocket.Connect(address, iStatus);

	iConnected = ETrue;
}
开发者ID:fedor4ever,项目名称:devicedbgsrvs,代码行数:48,代码来源:TrkSocketCommPort.cpp

示例14: connect_test

static int connect_test()
{
	RSocketServ rSockServ;
	RSocket rSock;
	TInetAddr inetAddr;
	TRequestStatus reqStatus;
	char buffer[16];
	TPtrC8 data((const TUint8*)buffer, (TInt)sizeof(buffer));
 	int rc;
	
	rc = rSockServ.Connect();
	if (rc != KErrNone)
		return rc;
	
	rc = rSock.Open(rSockServ, KAfInet, KSockDatagram, KProtocolInetUdp);
    	if (rc != KErrNone) 
    	{    		
    		rSockServ.Close();
    		return rc;
    	}
   	
    	inetAddr.Init(KAfInet);
    	inetAddr.Input(_L("127.0.0.1"));
    	inetAddr.SetPort(80);
    	
    	rSock.Connect(inetAddr, reqStatus);
    	User::WaitForRequest(reqStatus);

    	if (reqStatus != KErrNone) {
		rSock.Close();
    		rSockServ.Close();
		return rc;
    	}
    
    	rSock.Send(data, 0, reqStatus);
    	User::WaitForRequest(reqStatus);
    	
    	if (reqStatus!=KErrNone) {
    		rSock.Close();
    		rSockServ.Close();
    		return rc;
    	}
    	
    	rSock.Close();
    	rSockServ.Close();
	return KErrNone;
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:47,代码来源:sock.c

示例15: StartRead

//
// Start asynchronous recv() operation
//
pj_status_t CIoqueueCallback::StartRead (pj_ioqueue_op_key_t *op_key,
        void *buf, pj_ssize_t *size,
        unsigned flags,
        pj_sockaddr_t *addr, int *addrlen)
{
    PJ_ASSERT_RETURN (IsActive() ==false, PJ_EBUSY);
    PJ_ASSERT_RETURN (pending_data_.common_.op_key_==NULL, PJ_EBUSY);

    flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC;

    pending_data_.read_.op_key_ = op_key;
    pending_data_.read_.addr_ = addr;
    pending_data_.read_.addrlen_ = addrlen;

    aBufferPtr_.Set ( (TUint8*) buf, 0, (TInt) *size);

    type_ = TYPE_READ;

    if (addr && addrlen) {
        sock_->Socket().RecvFrom (aBufferPtr_, aAddress_, flags, iStatus);
    } else {
        aAddress_.SetAddress (0);
        aAddress_.SetPort (0);

        if (sock_->IsDatagram()) {
            sock_->Socket().Recv (aBufferPtr_, flags, iStatus);
        } else {
            // Using static like this is not pretty, but we don't need to use
            // the value anyway, hence doing it like this is probably most
            // optimal.
            static TSockXfrLength len;
            sock_->Socket().RecvOneOrMore (aBufferPtr_, flags, iStatus, len);
        }
    }

    SetActive();
    return PJ_EPENDING;
}
开发者ID:max3903,项目名称:SFLphone,代码行数:41,代码来源:ioqueue_symbian.cpp


注:本文中的TInetAddr::SetPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。