How to make a secondary connection

Once a device has been discovered, an IrDA connect may be initiated.

In terms of the IrDA specification, a successful return from connect will put the two machines into the link state (or NRM) after having completed both the IrLAP and IrLMP connect procedures.

Use a listening socket (sock1 in the code fragment) to set up the IrDA protocol stack in a “wait for connect” state. The RSocket::Listen() call completes immediately and a NULL acceptor socket (sock2 in the code fragment) is set up to accept the incoming connection on the listening socket. In this example, a maximum of 5 of these connections will be accepted on one particular socket home port ID before RSocket::Accept() fails.

Once the accept call returns successfully, a RSocket::Read() may be queued on the acceptor socket (sock2). If the client code requires a discovery indication to be signalled in some way, a discovery Ioctl request can be queued at any stage prior to the RSocket::Accept() call. The format of the discovery Ioctl request is outlined in a later section.

RSocketServ ss;
...
//
// BIND TO HOME PORT 0x02
//
TRequestStatus stat;

addr.SetPort(0x02);
sock1.Bind(addr,stat);              // Bind to socket
User::WaitForRequest(stat);         // stat should return KErrNone
//
// LISTEN - RETURNS IMMEDIATELY AFTER SETTING UP SOCKET.
//
sock1.Listen(5,stat);               // Wait for Connect....Listening
User::WaitForRequest(stat);         // stat should return KErrNone
//
// CREATE ACCEPT SOCKET
//
RSocket sock2; 
sock2.Open(ss);                     // Open NULL socket.
sock1.Accept(sock2,stat);           // Create ACCEPT socket - only
User::WaitForRequest(stat);         // return after connect accepted.
                                    // stat should return KErrNone
//
// CONNECTION ACCEPTED! QUEUE READ ON ACCEPT SOCKET
//
sock2.Read(data,stat);
User::WaitForRequest(stat);         // stat should return KErrNone