1 / 13

Symbian 网络应用开发

Symbian 网络应用开发. 主要内容. Symbian 通信体系结构 Socket 应用开发 HTTP 协议应用开发. Symbian 通信体系结构. Socket 应用开发. 客户端 / 服务器程序. Socket 应用开发. 套接字服务器会话 套接字服务器会话类 RSocketServ m_sockServ; User::LeaveIfError(m_sockServ.Connect()); 网络连接管理类 RConnection. Socket 应用开发. 套接字 RSocket m_socket;

Download Presentation

Symbian 网络应用开发

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Symbian网络应用开发

  2. 主要内容 • Symbian通信体系结构 • Socket应用开发 • HTTP协议应用开发

  3. Symbian通信体系结构

  4. Socket应用开发 • 客户端/服务器程序

  5. Socket应用开发 • 套接字服务器会话 • 套接字服务器会话类 RSocketServ m_sockServ; User::LeaveIfError(m_sockServ.Connect()); • 网络连接管理类 • RConnection

  6. Socket应用开发 • 套接字 RSocket m_socket; User::LeaveIfError( m_socket.Open( m_socketServ, KAfInet,KSockStream,KProtocolInetTcp ) ); m_socket.Connect( serverAddr , iStatus ); //接收和发送数据 void Recv(TDes8& aDesc,TUint flags,TRequestStatus& aStatus); void Recv(TDes8& aDesc,TUint flags,TRequestStatus& aStatus,TSockXfrLength& aLen); void RecvOneOrMore(TDes8& aDesc,TUint flags, TRequestStatus& aStatus,TSockXfrLength& aLen); void Send(const TDesC8& aDesc,TUint someFlags, TRequestStatus& aStatus,TSockXfrLength& aLen);

  7. Socket应用开发 • 域名解析基本过程 • (1)创建域名解析器实例 RHostResolver m_resolver; //解析结果 TNameEntry m_nameEntry; //被解析器找到的域名记录 TNameRecord m_nameRecord; • (2)打开域名解析器 User::LeaveIfError( m_resolver.Open( m_socketServ,KAfInet, KProtocolInetUdp ) );

  8. Socket应用开发 • 域名解析基本过程 • (3)发送域名解析请求 TBuf<50> serverName; serverName.Append(_L("www.sohu.com")); m_resolver.GetByName( serverName, m_nameEntry, iStatus );

  9. Socket应用开发 • 域名解析基本过程 • (4)处理域名解析结果 void CConnection::RunL() { m_resolver.Close(); if ( iStatus == KErrNone ) { // 域名解析成功 m_nameRecord = m_nameEntry(); //取出域名记录 ConnectL( TInetAddr::Cast( m_nameRecord.iAddr ). Address() ); } else { // 域名解析失败 // 做错误处理 } }

  10. Socket应用开发 • 安全套接字 • 使用安全套接字的基本过程: • (1)建立和打开一个RSocket套接字 使用RSocket::Open打开一个TCP/IP套接字RSocket。 使用RSocket::Connect()连接服务器。 • (2)由RSocket句柄创建一个 CSecureSocket对象 • (3)在安全套接字上调用StartClientHandshake() • (4)使用CSecureSocket的Send()和Recv()安全的传输数据

  11. HTTP协议应用开发 • HTTP会话 RHTTPSession iSession; //在类的ConstructL()方法中,打开会话 iSession.OpenL();

  12. HTTP协议应用开发 • HTTP事务 • 事务运行在会话上 • 事务由请求和响应组成 • HTTP事务类 • RHTTPTransaction • 侦听器接口类 class MHTTPTransactionCallback { public: virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) =0; virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent) =0; };

  13. HTTP协议应用开发 • HTTP事务 • 事务运行在会话上 • 事务由请求和响应组成 • HTTP事务类 • RHTTPTransaction • 侦听器接口类 class MHTTPTransactionCallback { public: virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) =0; virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent) =0; };

More Related