zoukankan      html  css  js  c++  java
  • 如何使用已连接的接入点

    Contents

     [hide]

    简介

    你可以使用已存在的连接RConnection,用来建立到互联网的连接。这将会节省资源和内存。

    RConnection可以列出已存在的连接。示例代码中我们查找已存在的连接,并通过IAP接入。如果没有选择激活的连接,那么就会创建一个新的。在示例代码中没有处理错误信息。

    MMP文件

    LIBRARY http.lib

    LIBRARY ecom.lib

    LIBRARY esock.lib

    LIBRARY commdb.lib

    CAPABILITY NetworkServices

    头文件

    #include <http.h>
    #include <es_sock.h>
    #include <commdbconnpref.h>

    Source file

    // Selected IAP
    TInt selectedIap=6;
     
    // Open socket server and connection
    RHTTPSession session; // TODO: Set to your class member variable
    RSocketServ socketServ; // TODO: Set to your class member variable
    RConnection connection; // TODO: Set to your class member variable
    TCommDbConnPref connPref; // TODO: Set to your class member variable
    socketServ.Connect();
    connection.Open(iSocketServ);
     
    // Search through existing connections.
    // If there is already a connection that matches the given IAP, try to attach to
    // existing connection.
    TBool connected(EFalse);
    TConnectionInfoBuf connInfo;
    TUint count;
    if ( connection.EnumerateConnections(count) == KErrNone )
    {
    for (TUint i=1; i<=count; i++)
    {
    // Note: GetConnectionInfo expects 1-based index
    if ( connection.GetConnectionInfo( i, connInfo ) == KErrNone )
    {
    if ( connInfo().iIapId == selectedIap )
    {
    if ( connection.Attach(connInfo, RConnection::EAttachTypeNormal)
    == KErrNone )
    {
    connected = ETrue;
    break;
    }
    }
    }
    }
    }
     
    // Is there an active connection?
    if ( !connected )
    {
    // Could not attach to the existing connection.
    // => Start a new connection.
    connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connPref.SetIapId(selectedIap);
    connection.Start(connPref);
    }
     
    // Open session
    session.OpenL();
     
    // Set the session's connection info...
    RStringPool strPool = session.StringPool();
    RHTTPConnectionInfo connInfo = session.ConnectionInfo();
     
    // ...to use the socket server
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
     
    // ...to use the connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(connection))) );
     
     
     
     
    // TODO: Remember to close handles in your class destructor, such as:
    CYourClass::~CYourClass()
    {
    session.Close(); // Close handles in this order
    connection.Close();
    socketServ.Close();
    }

    相关连接

    TSS000056 - How can I determine active connections?

  • 相关阅读:
    浅析Linux操作系统是如何工作的(思维导图)
    【Git】创建一个空分支
    ubuntu13.04更新源
    【Linux操作系统分析】设备驱动处理流程
    django-xss攻击原理与防范
    django—xadmin中集成富文本编辑器ueditor
    垃圾回收机制
    元组-不仅仅是不可变的列表
    不一样的列表
    Python数据模型
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/1848791.html
Copyright © 2011-2022 走看看