1. because tcp port < 1024 is reserved by system, so normally not use the tcp port, u can try 3456 or other bigger port.
2. I suggest you that use RConnection class, so the
User::LeaveIfError( iListenSckt.Open( iScktServ, KAfInet, KSockStream, KProtocolInetTcp )
change to
User::LeaveIfError( iListenSckt.Open( iScktServ, KAfInet, KSockStream, KProtocolInetTcp, iConnection ) etc
3. iDataSckt is which you need open too, so before accept, you need call iDataSckt.Open
4. make sure that you have CActiveSchedule
and next is my some code with listen, hope it is help to you
Code:
TBool CListenSocket::ListenL()
{
User::LeaveIfError(iListenSocket.Open( *(iIapEngine->GetSocketServ()), KAfInet, KSockStream,
KProtocolInetTcp, *(iIapEngine->GetConnection()) ));
const TInt LISTEN_MIN = 6000;
const TInt LISTEN_MAX = 7000;
TUint port = LISTEN_MIN;
for ( ; port < LISTEN_MAX; port++)
{
iListenAddr.SetPort(port);
if ( iListenSocket.Bind(iListenAddr) == KErrNone )
{
break;
}
}
if ( port >= LISTEN_MAX )
{
iListenSocket.Close();
return EFalse;
}
iListenSocket.Listen(1);
// Create blank socket
iAcceptSocket.Open(*(iIapEngine->GetSocketServ()));
// Issue an accept
iListenSocket.Accept(iAcceptSocket, iStatus);
SetActive();
ps. there is chinese discussion board, you can use chinese