Symbian3/PDK/Source/GUID-24CF2B94-5F10-57D9-B0D4-E56A80266595.dita
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
--- a/Symbian3/PDK/Source/GUID-24CF2B94-5F10-57D9-B0D4-E56A80266595.dita	Tue Mar 30 11:42:04 2010 +0100
+++ b/Symbian3/PDK/Source/GUID-24CF2B94-5F10-57D9-B0D4-E56A80266595.dita	Tue Mar 30 11:56:28 2010 +0100
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
-<!-- This component and the accompanying materials are made available under the terms of the License 
-"Eclipse Public License v1.0" which accompanies this distribution, 
-and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
-<!-- Initial Contributors:
-    Nokia Corporation - initial contribution.
-Contributors: 
--->
-<!DOCTYPE concept
-  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
-<concept xml:lang="en" id="GUID-24CF2B94-5F10-57D9-B0D4-E56A80266595"><title> Implementing a Listener</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>A Listener opens and prepares the sockets to listen for incoming socket connection requests at the TCP layer. This section describes how to implement a Listener. </p> <section><title>Required background</title> <p>Before you start, you must understand: </p> <ul><li id="GUID-F9067DBC-CC31-56DA-B852-078186AD4043"><p>Socket programming and configurations. </p> </li> </ul> </section> <section><title>Procedure</title> <ol id="GUID-68FFDC34-68F7-553D-9CF9-80F4B170A427"><li id="GUID-4D9223E6-28F9-5EE3-AA33-1752C51815A4"><p>Create <codeph>RCONNECTION()</codeph>. </p> <ol id="GUID-396D720E-CF14-58C0-A2CB-20B52BE309AF"><li id="GUID-5AC52535-AF75-5387-A38F-3413661BF5BB"><p>Create a session with the socket server: </p> <codeblock id="GUID-D620558B-4603-54A5-8709-D32ED5CFF7FD" xml:space="preserve">RSocketServ::Connect;</codeblock> </li> <li id="GUID-4FF6738C-9506-5832-A544-3FC7EA06CB34"><p>Open a TCP socket on the new session: </p> <codeblock id="GUID-19CC8A8E-747D-53BF-927D-2F734717C9E5" xml:space="preserve">RSocket::Open(iSS, KAfInet, KSockStream, KProtocolInetTcp,iSubconn);</codeblock> </li> </ol> <p>Optionally, to open a new connection over a session, perform the following steps: </p> <ol id="GUID-E8F1BA77-0A3D-50C5-9E39-E0D79892D016"><li id="GUID-C66616DC-BE75-51E9-B7A8-5F3A3707678B"><p>Create a new session with the socket server: </p> <codeblock id="GUID-9662F0F8-B1F1-59BC-8E83-D0E537479A4D" xml:space="preserve">RSocketServ::Connect();</codeblock> </li> <li id="GUID-E7949B6F-1527-5A20-AFDA-38A810271AD6"><p>Open a new connection over the session: </p> <codeblock id="GUID-7390B03B-B8CD-5028-A860-C927A19E4DDC" xml:space="preserve">RCONNECTION::Open(iSS);</codeblock> </li> <li id="GUID-B7E7663D-F5E0-57FB-8784-D5EAF41B7EB4"><p>Modify the <codeph>commsDB</codeph> settings: </p> <codeblock id="GUID-4D40A978-C30A-57EB-ABE5-379FD52727BA" xml:space="preserve">TCommDbConnPref prefs;
-        prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);</codeblock> <p> </p> </li> <li id="GUID-CEA655D0-BA1A-5F60-AAF7-0C13C318949A"><p>Start the connection: </p> <codeblock id="GUID-64A87704-1031-5AE6-BBA9-958872C41BB4" xml:space="preserve">RCONNECTION::Start(prefs);</codeblock> </li> <li id="GUID-6882BB67-EC13-5A78-A975-E2134CB2473A"><p>Open the default sub-connection over the new connection: </p> <codeblock id="GUID-8F745B02-12B9-5CE3-92ED-C7E8129D3C53" xml:space="preserve">RSubConnection::Open(iSS, RSubConnection::EAttachToDefault, iConn);</codeblock> </li> <li id="GUID-C4677F3B-84A1-5E72-B5EB-9D76414B1176"><p>Open a TCP socket on the sub-connection: </p> <codeblock id="GUID-5CCC373B-4E6C-57F7-BA2C-552AC40DD66D" xml:space="preserve">RSocket::Open(iSS, KAfInet, KSockStream, KProtocolInetTcp,iSubconn);</codeblock> <p>The socket type must be <b>Stream Socket</b>. </p> </li> </ol> </li> <li id="GUID-F4E68F36-A332-5346-B591-25E1EFCA502C"><p>Wait and accept new connection. </p> <ol id="GUID-58944725-72BB-5FAF-A3AF-F90DB503FC47"><li id="GUID-C853C3BA-7DD8-558F-A2BE-76CF315634C0"><p>Bind the socket to the appropriate IP address and port number. For example, the port number for PTP-IP is 1540. </p> <codeblock id="GUID-78C3E1B4-08B5-537F-AA04-1732184CCBA9" xml:space="preserve">RSocket::Bind(anyAddrOnPort);</codeblock> <codeblock id="GUID-C2360A38-4981-52E3-9C17-D1E646EFC235" xml:space="preserve">RSocket::Listen(queuesize);</codeblock> </li> <li id="GUID-0816BFF6-E70F-5470-835E-1DD81088D66B"><p>Call the appropriate <codeph>Listen()</codeph> API on the socket. </p> </li> </ol> </li> <li id="GUID-09D059EA-FA10-5FF3-BCF4-F4FF136CCC1B"><p>Acquire the socket. </p> <p>To get a new blank socket, use <codeph>NewSocketL()</codeph>, This method returns a reference to the new blank socket. </p> <codeblock id="GUID-C01F0178-C5C6-59B1-A558-45BCA700DCB3" xml:space="preserve">RSocket&amp; socket(MPTPIPController&amp;::NewSocketL());</codeblock> <p> <b> Note:</b> There is a limit to the number of sockets returned in each session. </p> <p>You must then call the <codeph>Accept()</codeph> API using the blank socket to accept and bind the remote connection request with the given socket. </p> <codeblock id="GUID-494FD3B8-D47D-5C84-A030-EE840D29DAE5" xml:space="preserve">RSocket::Accept(socket, iStatus); </codeblock> </li> </ol> </section> </conbody><related-links><link href="GUID-2D872656-7FD3-56D2-B084-8CC84E8453A4.dita"><linktext>MTP over
-                PTP-IP Overview</linktext> </link> <link href="GUID-143DAD71-9BCA-52D3-8BC8-AE80DBF05636.dita"><linktext>Using PTP-IP
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
+<!-- This component and the accompanying materials are made available under the terms of the License 
+"Eclipse Public License v1.0" which accompanies this distribution, 
+and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
+<!-- Initial Contributors:
+    Nokia Corporation - initial contribution.
+Contributors: 
+-->
+<!DOCTYPE concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<concept xml:lang="en" id="GUID-24CF2B94-5F10-57D9-B0D4-E56A80266595"><title> Implementing a Listener</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>A Listener opens and prepares the sockets to listen for incoming socket connection requests at the TCP layer. This section describes how to implement a Listener. </p> <section><title>Required background</title> <p>Before you start, you must understand: </p> <ul><li id="GUID-F9067DBC-CC31-56DA-B852-078186AD4043"><p>Socket programming and configurations. </p> </li> </ul> </section> <section><title>Procedure</title> <ol id="GUID-68FFDC34-68F7-553D-9CF9-80F4B170A427"><li id="GUID-4D9223E6-28F9-5EE3-AA33-1752C51815A4"><p>Create <codeph>RCONNECTION()</codeph>. </p> <ol id="GUID-396D720E-CF14-58C0-A2CB-20B52BE309AF"><li id="GUID-5AC52535-AF75-5387-A38F-3413661BF5BB"><p>Create a session with the socket server: </p> <codeblock id="GUID-D620558B-4603-54A5-8709-D32ED5CFF7FD" xml:space="preserve">RSocketServ::Connect;</codeblock> </li> <li id="GUID-4FF6738C-9506-5832-A544-3FC7EA06CB34"><p>Open a TCP socket on the new session: </p> <codeblock id="GUID-19CC8A8E-747D-53BF-927D-2F734717C9E5" xml:space="preserve">RSocket::Open(iSS, KAfInet, KSockStream, KProtocolInetTcp,iSubconn);</codeblock> </li> </ol> <p>Optionally, to open a new connection over a session, perform the following steps: </p> <ol id="GUID-E8F1BA77-0A3D-50C5-9E39-E0D79892D016"><li id="GUID-C66616DC-BE75-51E9-B7A8-5F3A3707678B"><p>Create a new session with the socket server: </p> <codeblock id="GUID-9662F0F8-B1F1-59BC-8E83-D0E537479A4D" xml:space="preserve">RSocketServ::Connect();</codeblock> </li> <li id="GUID-E7949B6F-1527-5A20-AFDA-38A810271AD6"><p>Open a new connection over the session: </p> <codeblock id="GUID-7390B03B-B8CD-5028-A860-C927A19E4DDC" xml:space="preserve">RCONNECTION::Open(iSS);</codeblock> </li> <li id="GUID-B7E7663D-F5E0-57FB-8784-D5EAF41B7EB4"><p>Modify the <codeph>commsDB</codeph> settings: </p> <codeblock id="GUID-4D40A978-C30A-57EB-ABE5-379FD52727BA" xml:space="preserve">TCommDbConnPref prefs;
+        prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);</codeblock> <p> </p> </li> <li id="GUID-CEA655D0-BA1A-5F60-AAF7-0C13C318949A"><p>Start the connection: </p> <codeblock id="GUID-64A87704-1031-5AE6-BBA9-958872C41BB4" xml:space="preserve">RCONNECTION::Start(prefs);</codeblock> </li> <li id="GUID-6882BB67-EC13-5A78-A975-E2134CB2473A"><p>Open the default sub-connection over the new connection: </p> <codeblock id="GUID-8F745B02-12B9-5CE3-92ED-C7E8129D3C53" xml:space="preserve">RSubConnection::Open(iSS, RSubConnection::EAttachToDefault, iConn);</codeblock> </li> <li id="GUID-C4677F3B-84A1-5E72-B5EB-9D76414B1176"><p>Open a TCP socket on the sub-connection: </p> <codeblock id="GUID-5CCC373B-4E6C-57F7-BA2C-552AC40DD66D" xml:space="preserve">RSocket::Open(iSS, KAfInet, KSockStream, KProtocolInetTcp,iSubconn);</codeblock> <p>The socket type must be <b>Stream Socket</b>. </p> </li> </ol> </li> <li id="GUID-F4E68F36-A332-5346-B591-25E1EFCA502C"><p>Wait and accept new connection. </p> <ol id="GUID-58944725-72BB-5FAF-A3AF-F90DB503FC47"><li id="GUID-C853C3BA-7DD8-558F-A2BE-76CF315634C0"><p>Bind the socket to the appropriate IP address and port number. For example, the port number for PTP-IP is 1540. </p> <codeblock id="GUID-78C3E1B4-08B5-537F-AA04-1732184CCBA9" xml:space="preserve">RSocket::Bind(anyAddrOnPort);</codeblock> <codeblock id="GUID-C2360A38-4981-52E3-9C17-D1E646EFC235" xml:space="preserve">RSocket::Listen(queuesize);</codeblock> </li> <li id="GUID-0816BFF6-E70F-5470-835E-1DD81088D66B"><p>Call the appropriate <codeph>Listen()</codeph> API on the socket. </p> </li> </ol> </li> <li id="GUID-09D059EA-FA10-5FF3-BCF4-F4FF136CCC1B"><p>Acquire the socket. </p> <p>To get a new blank socket, use <codeph>NewSocketL()</codeph>, This method returns a reference to the new blank socket. </p> <codeblock id="GUID-C01F0178-C5C6-59B1-A558-45BCA700DCB3" xml:space="preserve">RSocket&amp; socket(MPTPIPController&amp;::NewSocketL());</codeblock> <p> <b> Note:</b> There is a limit to the number of sockets returned in each session. </p> <p>You must then call the <codeph>Accept()</codeph> API using the blank socket to accept and bind the remote connection request with the given socket. </p> <codeblock id="GUID-494FD3B8-D47D-5C84-A030-EE840D29DAE5" xml:space="preserve">RSocket::Accept(socket, iStatus); </codeblock> </li> </ol> </section> </conbody><related-links><link href="GUID-2D872656-7FD3-56D2-B084-8CC84E8453A4.dita"><linktext>MTP over
+                PTP-IP Overview</linktext> </link> <link href="GUID-143DAD71-9BCA-52D3-8BC8-AE80DBF05636.dita"><linktext>Using PTP-IP
                 Controller</linktext> </link> <link href="GUID-7CFE584D-B605-5A3E-9294-84A28003000B.dita"><linktext>Implementing a Filter</linktext> </link> </related-links></concept>
\ No newline at end of file