TCP/IP Socket Server: problems creating listening socket

Login to reply to this topic.
Thu, 2008-05-08 11:30
Joined: 2008-05-08
Forum posts: 6

Hi guys,

first of all thanks for this great and helpful forum!
I'm new in symbian c++ and I've found a lot of
tips to solve problems here.

Now I'm trying to build up a server socket with RSocket
API (console application) but I'm facing problems
during my first step:
open a TCP listening socket on 127.0.0.1:1234

I've structured my Test Server as an Active Object
where, after all Sockets initialization, it executes
an accept(), a setActive() statement and finally
the CActiveScheduler::Start().
-------------------------
The matter is this: my program, running on emulator, seems
to stop waiting for incoming connection
but it doesn't create any TCP listening socket on
port 1234!
-------------------------
I work with Windows XP and using "netstat -a -n" command
I cannot see any new TCP socket listening on port 1234.
Putting console->Write() everywhere,
I've noticed that my RunL() method is never called and
the program block on CActiveScheduler::Start() statement.

Thanks again just for looking this long post! Smiling

Roberto

// Active Object's Header--------------------
//-------------------------------------------
class CActiveConnection : public CActive {
public:       
        ~CActiveConnection();
        static CActiveConnection* NewL();
        static CActiveConnection* NewLC();
        void StartL();
private:
        CActiveConnection();
        void ConstructL();
        void RunL();        // From CActive Handle completion
        void DoCancel();
        enum TActiveConnectionState
                {
                EUninitialized, // Uninitialized
                EInitialized, // Initalized
                EError // Error condition
                };
private:
        TInt iState; // State of the active object
        TInt returnStat;
        TRequestStatus iStatus;
       
        RSocketServ iSocketServer;
        RSocket iSocket;
        RSocket iListenSocket;
};
//-------------------------------------------
// Member functions--------------------------
//-------------------------------------------
CActiveConnection::CActiveConnection() : CActive(EPriorityStandard) { }

CActiveConnection* CActiveConnection::NewLC() {
                CActiveConnection* self = new ( ELeave ) CActiveConnection();
                CleanupStack::PushL(self);
                self->ConstructL();
                return self; }

CActiveConnection* CActiveConnection::NewL() {
                CActiveConnection* self = CActiveConnection::NewLC();
                CleanupStack::Pop(); // self;
                return self; }

void CActiveConnection::ConstructL() { CActiveScheduler::Add(this); }

CActiveConnection::~CActiveConnection()        { Cancel(); }

void CActiveConnection::StartL() {
                Cancel();
                iState = EUninitialized;
                TInetAddr iAddress(KInetAddrLoop, 1234);
               
                // Connect Socket Server
                iSocketServer.Connect();
               
                // Open della Listening Socket :
                iListenSocket.Open(iSocketServer, KAfInet,KSockStream, KProtocolInetTcp);
               
                // Bind the listening socket to the required port.
                iListenSocket.Bind(iAddress);
               
                iListenSocket.Listen(1);

                // open a blank socket
                iSocket.Open(iSocketServer);

                iListenSocket.Accept(iSocket, iStatus);
                SetActive();
        }

void CActiveConnection::RunL() {
                printConsole(_L("executing RUNL!\n"));
                if (iState == EUninitialized) {
                        // Do something the first time RunL() is called
                } else
                        if (iState != EError) {
                                // Do something
                        }
        }
//-------------------------------------------
// Test function [to make first request]-----
// called by main----------------------------
LOCAL_C void DoStartL() {
        CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
        CleanupStack::PushL(scheduler);
        CActiveScheduler::Install(scheduler);
       
        CActiveConnection* active = CActiveConnection::NewL();       
        active->StartL();
       
        CActiveScheduler::Start();
        console->Write(_L("..after CActiveScheduler::Start()!\n"));
        CleanupStack::PopAndDestroy(scheduler);
}
//-------------------------------------------


Tue, 2008-05-13 10:55
Joined: 2008-05-08
Forum posts: 6
Re: TCP/IP Socket Server: problems creating listening socket

can anybody help me? maybe it's just a silly error but it's quite urgent
Thanks in adv

Tue, 2008-05-13 11:21
Joined: 2003-12-05
Forum posts: 588
Re: TCP/IP Socket Server: problems creating listening socket

You have made the classical newbie error in Active object programming, when declaring your own iStatus member variable. Do not do that, but use the member variable inherited from CActive.

Tue, 2008-05-13 16:38
Joined: 2008-05-08
Forum posts: 6
Re: TCP/IP Socket Server: problems creating listening socket

Hi Andreas,

thanks for your reply! It's true, I was wrong declaring my own iStatus member variable.
However, changing class declaration by removing iStatus member variable the matter is still there!
This program block on CActiveScheduler::Start(); statement, without creating any listening tcp socket.
This morning I've tried to do some test, running program in debug mode and I've seen things like those:

(1) setting iAddress = INET_ADDR(127,0,0,1)
All statements ends without errors (open, bind, listen), but the accept() set the iStatus value to -2147483627
After the statement setActive(), member variable iActive goes to 1and the program blocks on CActiveScheduler::Start();
Typing "netstat -a -n" I cannot see any tcp socket opened on a generic X.X.X.X:1234 (and so no 127.0.0.1:1234 opened)

[reading lots of the post, I read about people like me, who cannot create a local tcp socket on localhost address.
For someone of them, changing the iAddress with the real IP address of the configured NIC, makes things working.]

(2) setting iAddress = INET_ADDR(146,48,99,94) [my local IP address]
All statements before bind(iAddress) ends without errors but bind return -1 value (Unable to find the specified object?? but why??).
Then iStatus, after accept() statement takes -18 value (KErrNotReady, maybe due to iListening socket not initialized)
In this case, RunL method starts but tcp socket, still doesn't appear in the listening tcp sockets of the system.

Any ideas?!

I'm using SDK 2nd FP 3. After the first SDK installation, every time I reinstall my SDK, I get an error message like that:
"failed to install npacketadmin", "failed to start npacketadmin service".
But I removed and then reinstalled SDK three or four times and this message always appears.
If this is the matter, how could I remove this service? (to reinstall SDK like the first time, when I didn't get npackeadmin installation error)

Thanks for help

Tue, 2008-05-13 19:52
Joined: 2003-12-05
Forum posts: 588
Re: TCP/IP Socket Server: problems creating listening socket

CActiveScheduler::Start does not block, but starts to wait for any asynchronous events to complete by calling User::WaitForAnyRequest. You properly set the active object active before calling CActiveScheduler::Start. Since there is no asynch requests completing, the thread is suspended by the OS (if no other events complete, e.g. UI events).

Now, what is your asynch request you wait for? It's the listening of new connections. RunL is called when a new connection comes in. Have you tried to connect to the socket with some other client application in the emulator?

PS: I bet the iStatus value of -2147483627 is KRequestPending, even though I'm not quite sure of this... That's correct, because you are now waiting for the pending async request to complete. The client API of the socket server sets this value.

Wed, 2008-05-14 12:25
Joined: 2008-05-08
Forum posts: 6
Re: TCP/IP Socket Server: problems creating listening socket

Thank you Andreas for your quick replies!

Trying to test what you've explained to me, yesterday I wrote a console application which is a simple tcp client.

However maybe there is a problem with my EPOC Emulator (SDk 2nd FP 3) which I cannot understand.

(Test 1) If I try to run both my programs (1) listening server and (2) tcp client directly from CarbIDE (v1.3).
Two instances of EPOC emulator start but during the starting of the second one,
the "ERROR: cannot bind to port 3651, error 10048" occurs. Perhaps just one instance per time, of EPOC emulator, is allowed.

(Test 2) However, if I try to start emulator from
start -> All Programs -> Series 60 Developer Tools -> Second Edition SDK Feature Pack 3 -> C++ -> emulator (debug)
The emulator seems to start but just the skin of the emulator is displayed!
There isn't any Application Grid! Just a white square in the center of skin emulator!
(I neither cannot use the window button "File" and "Tools")

I've done this test because I've thougth I could connect to my listening server via browser installed on emulator.
(putting local address and right port)
But due to problems explained above, I cannot do that!
It seems like I can just run console application with my installed emulator (I cannot run UI application)

Following the release notes, this time (and not like the others as the ones I've done and described in the last post) I've uninstalled
without any errors and installed again SDK, but nothing is changed.

Smiling It's quite a nightmare when there's no light in problem solving!

Thanks again for your help!!

Wed, 2008-05-14 12:31
Joined: 2003-12-05
Forum posts: 588
Re: TCP/IP Socket Server: problems creating listening socket

Yep, usually when you debug a console app, no GUI environment is loaded. You might investigate if the emulator has any way of launching a console app. If not, you need to build a small application to launch the console application. Or switch to using GUI apps only in tests.

Wed, 2008-05-14 14:57
Joined: 2008-05-08
Forum posts: 6
Re: TCP/IP Socket Server: problems creating listening socket

If I cannot find a way to start up both console applications (server and client), I could test them using GUI apps!
It's a good idea! thanks!
..however before working on your new issue I need to solve a basic problem that stops my work:

Now Andreas I really don't know why but I cannot execute GUI apps on my emulator (like I wrote on the last post). It blocks its execution after loaded the skin, and the typical Nokia menu does not appear.
Instead of Nokia grid application (typical menu) a white screen is displayed.

If I try to run a simple GUI Hello World, from carbIDE, happens the same thing:
1) emulator loads the skin of the mobile
2) then stops, without loading GUI Hello World. GUI is replaced by this deep white square.

It is happened with SDK 2nd FP3 and now I am facing the same matter with my new installation of SDK v2.0 CW (for my 6600).

Do you think could be a problem due to wrong version of JRE? I've installed, all together, 1.4.2, 1.5, 1.6.

Or maybe there's something I don't understand about all this architetture.
But it sounds strange that I can't access to emulated Symbian OS environment, maybe I've done a really silly mistake!

Wed, 2008-05-14 19:01
Joined: 2003-12-05
Forum posts: 588
Re: TCP/IP Socket Server: problems creating listening socket

I cannot execute GUI apps on my emulator (like I wrote on the last post). It blocks its execution after loaded the skin, and the typical Nokia menu does not appear. Instead of Nokia grid application (typical menu) a white screen is displayed.

How long have you waited? Has the emulator started, ever? The startup can be really slow, especially if you do not have a fast PC. You may have to wait several minutes for the emulator to start completely (depending on the PC). Can you launch the emulator from the command prompt (using command epoc or epoc -rel (which launches the release emulator which is a bit faster)).

Also you mentioned installation problems. Describe your environment. Vista has some problems, XP is recommended. Also you need to install everything with admin rights.

Wed, 2008-05-14 21:29
Joined: 2008-05-08
Forum posts: 6
Re: TCP/IP Socket Server: problems creating listening socket

Good evening! (in Italy it's 9.41 pm)

I will never stop to thank for your help Andreas. I'm trying to solve all those matters to port a daemon
in Symbian C++ which I wrote in C language. This work is part of my thesis and so, every helpful word
is like gold for me in this moment!

(1) I've waited about for 15 minutes, and this emulator never started! It was visible just the mobile emulator skin, with a white screen in the center (instead of normal GUI grid application). Like you wrote to me, I've tried to
launch it by console, but nothing changed.

Reading lots of post, I've discovered that other people like me, has got the same matter. Some of them call
this "blank screen emulator problem". The most popular solution posted is to look at the epoc.ini file
(in Epoc32\data folder) and check if the key _EPOC_DRIVE_D points to the right path of \epoc32\winscw\d folder.
(SDK folder installation). I tried this issue but it did not work for me.

(2) My configuration:

Hardware
Intel Centrino 1.6GHz, 1GB Ram

Software
Windows XP Home SP 2, with JRE 1.4.2, 1.5, 1.6 and JDK 1.5, 1.6 installed

TEST I installed those configurations facing all times blank screen problem:
(1) SDK Series 60 2nd FP3 + ActivePerl 5.6.1 build 365
(2) SDK Series 60 v2.0 CW + ActivePerl 5.6.1 build 365
(3) SDK Series 60 v2.0 CW + ActivePerl 5.1.8

  • Login to reply to this topic.