Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Accept() call in the RSocket class...

4 replies · 3,089 views · Started 21 August 2003

hi ,

i'm new to symbian and i'm certainly trying to play with the methods
in the RSockets classes for my TCP listener ...
i'll tell u what exactly i am doing..all my method calls are from the
RSockets class are in the foll sequence..

1. Open() method to create a blank socket
2. Bind() method used to bind to port (7030 in my case).
3. Listen() method to specify no. of client allowed to connect.
4. Accept() method to marry the incoming socket to the blank socket

which'll be passed as a parameter to the Accept() method.
It works perfectly fine uptil after the Accept() call...and then it
gives me a App.Closed panic error 17. I also checked out the error
codes and error 17 says - No Sockets currently open.

I dunno if my Accept call is right...coz the Accept(RSocket&
aBlankSocket) takes an RSocket (addressOf)object as a parameter and
the docs clearly says..it shud be an blank socket..so i make use of
the Open(RSocketServ& aServer) using an RSocket obj and pass it as a
parameter to the Accept() call...I wonder if this is correct...???

dunno where i am doing wat wrong...??
Am also adding my listener method...

Quote : *********************************

void CSocketsEngine::Listen() // <a name="ConnectL32">
{
//Initiate attempt to connect to a socket by IP address
if (iEngineStatus == ENotConnected)
{
//Open a TCP socket

User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet,

KSockStream, KProtocolInetTcp));
//Binding to port 7030
TUint portNum = 7030;
TSockAddr tsaPort;
tsaPort.SetPort(portNum);
TInt bindStat = iSocket.Bind(tsaPort);

if (bindStat == KErrNone) {
TBuf8<10> stat;
_LIT8(kStat,"%d"😉;
stat.Format(kStat,bindStat);
iConsole.ErrorNotify(_L("Bind Success"😉,

iEngineStatus);
}

//Listening for socket connections
TUint queSize = 5;
TUint popConn;
iConsole.ErrorNotify(_L("Before Listen Call"😉,

iEngineStatus);
popConn = iSocket.Listen(queSize);
TBuf8<5> statListen;

_LIT8(kstatListen,"%d"😉;
statListen.Format(kstatListen,popConn);
iConsole.ErrorNotify(_L("Listen QueSize Set"😉,

iEngineStatus);

//Accept every connection as and when it comes in

from the
//listen call..

RSocket blankRSock;
TInt blsock = 0;
blsock =

User::LeaveIfError(blankRSock.Open(iSocketServ));

TRequestStatus reqStat(blsock);
iSocket.Accept(blankRSock,reqStat);
TBuf8<20> inData;
inData.Zero();

TRequestStatus connStat;
if (reqStat == KErrNone) {
iConsole.ErrorNotify(_L("After Accept..."😉,

iEngineStatus);
}
blankRSock.Read(inData,reqStat);
iConsole.ErrorNotify(_L("The incoming value "😉,

iEngineStatus);

}
}

UnQuote : *******************************

the code compiles fine...but gives the app closed panic 17 error at
run time. I'd be happy happy happy if any o u cud give me any leads
regarding this.

thanks,
adios,
LearningCurve.

[quote="LearningCurve"][code:1]
RSocket blankRSock;
TInt blsock = 0;
blsock = User::LeaveIfError(blankRSock.Open(iSocketServ));
TRequestStatus reqStat(blsock);
iSocket.Accept(blankRSock,reqStat);
TBuf8<20> inData;
inData.Zero();

TRequestStatus connStat;
if (reqStat == KErrNone) {
iConsole.ErrorNotify(_L("After Accept..."), iEngineStatus);
}
blankRSock.Read(inData,reqStat);
[/code:1][/quote]

RSocket::Accept is not a blocking call. This means that you can not read from the socket, because it is not connected yet. You must either instruct your program to block until the blind socket is connected, or use an active object to get notified when the socket is connected.

Another thing. You check for success on the socket accept call and report that, but you don't do anything when it was not successful. So you will try to read from a socket, even if an error was reported.

thanx....cmathee...i am now...using waitForRequest() method call..as adviced by site admin newlc.com....and am able to connect to the phone...from remote machine...

adios,
LearningCurve.

Just remember that User::WaitForRequest is a blocking call. Your thread will not be able to do anything until the request is completed. If this is in your main app thread, then that means no user input is available. If this is in another thread, then that is not a problem.

One thing you may consider is to look at a timeout option in case the connection can not be made for whatever reason.

hi cmathee,

Am again having the foll. problem...

I am using the virtual serial port to connect to a java application on the remote machine. I am able to connect and also send data from the emulator.

But my TCP listener in the emulator is not able to accept client connections from remote clients...!!

I wonder if there cud be a problem with my client code....or if there is a restriction as to Virtual serial ports can't take incoming connections...

since...the remote ip and port displayed in the mRouter is correct whereas the from ip and port does not map to the local ip but some random ip address while trying to connect to remote machine from emulator of local machine.

I also tried putting the same code onto my 3650..but am able to connect to my computer from the phone...but am not able to connect to the phone...from the remote machine.....

I am also attaching my TCP listener code...please do check and clarify..if there is a problem with the code...or cud it be the operator whos blocked a range of port numbers...

i even tried other port no.s such as 20000 and 34570 etc...

Quote :
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//----------------------------------------------------------//
//This is the TCP listener method which will be called
//from the AppUI class on the click even of the listener.
//----------------------------------------------------------//
void CSocketsEngine::ListenL() // <a name="ConnectL32">
{

{

//Open a TCP socket
iSocketServ.Connect();
User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp));
//Binding to port 8030
TUint portNum = 8030;
TSockAddr tsaPort;
tsaPort.SetPort(portNum);
TInt bindStat = iSocket.Bind(tsaPort);

if (bindStat == KErrNone) {

iConsole.ErrorNotify(_L("Reeadd Listenn Bind Success"😉, iEngineStatus);
}


//Listening for socket connections
TUint queSize = 5;
TUint popConn;
iConsole.ErrorNotify(_L("Before Listen Call"😉, iEngineStatus);
popConn = iSocket.Listen(queSize);
TBuf8<5> statListen;

_LIT8(kstatListen,"%d"😉;
statListen.Format(kstatListen,popConn);
iConsole.ErrorNotify(_L("Listen QueSize Set"😉, iEngineStatus);

//Accept every connection as and when it comes in from the
//listen call..

RSocket blankRSock;
//RSocketServ blankRSockServ;

TInt blsock = 0;
blsock = User::LeaveIfError(blankRSock.Open(iSocketServ));

TRequestStatus reqStat(blsock);
iConsole.ErrorNotify(_L("Waiting for Client Connections..."😉, iEngineStatus);
iSocket.Accept(blankRSock,reqStat);
User::WaitForRequest(reqStat); // <<<<<= Wait for completion of iSocket.Accept

TBuf8<20> inData;
inData.Zero();

if (reqStat == KErrNone) {
iConsole.ErrorNotify(_L("After Accept..."😉, iEngineStatus);
iSocket.RecvOneOrMore(iMyBuffer, 0, iStatus, iMyDummyLength);
iConsole.ErrorNotify(_L("going to disp data"😉, iEngineStatus);
iConsole.PrintNotify(iMyBuffer);
iConsole.ErrorNotify(_L("diplayed data"😉, iEngineStatus);

}
//blankRSock.Read(inData,reqStat);
//User::WaitForRequest(reqStat); // <<<<<= Wait for completion of Read

iConsole.ErrorNotify(_L("going to change status to EConnecting"😉, iEngineStatus);
ChangeStatus(EConnecting);
iConsole.ErrorNotify(_L("changed stat calling setActive from ListenL"😉, iEngineStatus);
SetActive();
}

}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
UnQuote :

thanx,
adios,
LearningCurve.