Hi,
I am new to Symbian world. I really stuck with socket programming. I was doing simple client/server program. When I execute the Server program, I am getting error in the accept call. It is not waiting for any request to accept. That is why I have put the user::waitforrequest()
When I execute the client program it gives binding error 10048.
FYI: I am running two programs from same carbide window.
Here is my questions:
1. Why accept call does not block for the request to accept (may i am comparing unix socket programming, if rectify me concept)
2. In the connect we never bind, still why we are getting the binding error.
3. In my code I have given the port number 8100, but bind error gives the port number as 3651, I have not got why the port number is changed.
really I am confused, is it I need to run both program 2 different carbide C++, or am making any mistake in the code.
TInetAddr iAddr;
RSocketServ iSocketServ;
RSocket iSocket;
RSocket iAccept;
const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
iAddr.SetAddress(KInetAddrAny);
iAddr.SetPort(8100);
TRequestStatus iRequestStatus;
// Add to scheduler
TInt iReturn = iSocketServ.Connect();
if(iReturn != KErrNone)console->Write(_L("connected to RsocketServer"));
iReturn = iSocket.Open(iSocketServ,KAfInet,KSockStream,KProtocolInetTcp );
if(iReturn != KErrNone) console->Write(_L("open the socket\n"));
iReturn = iSocket.Bind(iAddr);
if(iReturn != KErrNone)console->Write(_L("Bind is successful\n"));
iReturn = iSocket.Listen(20);
if(iReturn != KErrNone)console->Write(_L("Listening successful\n"));
iReturn = iAccept.Open(iSocketServ);
if(iReturn != KErrNone)console->Write(_L("Blank Socket is created"));
iSocket.Accept(iAccept,iRequestStatus);
if(iRequestStatus.Int() != KErrNone)console->Write(_L("Success Accept\n"));
User::WaitForRequest(iRequestStatus);
console->Write(_L("Hello, world!\n"));
console->Write(_L("Hello, world!\n"));
Client:
LOCAL_C void MainL()
{
//
// add your program code here, example code below
//
RSocketServ iServSocket;
RSocket iSocket;
TRequestStatus aStatus;
TInetAddr destAddr;
destAddr.SetAddress(INET_ADDR(127,0,0,1));
destAddr.SetPort(8100);
iServSocket.Connect();
User::LeaveIfError(iSocket.Open(iServSocket,KAfInet,KSockStream,KProtocolInetTcp));
iSocket.Connect(destAddr,aStatus);
if(aStatus.Int()!=KErrNone) console->Write(_L("Error connecting socket...\n"));
console->Write(_L("Hello, world!\n"));
}
LOCAL_C void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
MainL();
// Delete active scheduler
CleanupStack::PopAndDestroy(scheduler);
}
Here is piece of code of client and server program:



