Well, after working around a few days with my concept I have to ask for the solution because I really do not understand how to use the ActiveC Objects correctly. I get Panics and never reach the RunL method. Would be great if someone could have a look into the code and tell me what I do wrong.
The Application is called ServerExample
I want to createa Socket where I can send data which I get in Symbian C++, to a Java application, Java part is working and I get already the data I want to send, but the connection does not really work.
I create the Server in the ConstructL of the ServerExampleContainer:
PHP Code:
iServerSocket=CServer::NewL(EPriorityHigh);
so far I hope everything works as it should, and a connection to the Symbian Server should be established.
As far as I know the Active Objects waits until it was "startet". I have a menu option and by pressing it the following method is called:
PHP Code:
iServerSocket->DoAsyncAction();
But the programm aborts with Panic: ServerExmaple E32User-CBase 46
when I want to set Object Active:
PHP Code:
void CServer::DoAsyncAction(/*MServerObserver& aOberserver*/){
//__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive));
//__ASSERT_ALWAYS(_Observer, User::Panic(KMyActivePanic, ENoObserver));
iState=EStartSystem;
//iObserver->ToState( ELookingUpIP );
[U]SetActive();[/U] // Starting the active sheduler?
}
So I do not really understand what I should do, I hope someone can help me 
PHP Code:
#include "Server.h"
// Two Phase Constructor
CServer* CServer::NewL(TInt aPriority/*,MServerObserver& aOberserver*/){
CServer* self = new (ELeave) CServer(aPriority/*, aOberserver*/);
CleanupStack::PushL(self);
//iObserver=aOberserver;
self->ConstructL();
CleanupStack::Pop();
return self;
}
// Second-phase constructor
void CServer::ConstructL(){
// Connect to Symbian Socketserver
User::LeaveIfError(iSocketServer.Connect());
// Creating a listening socket for incommin Java connections.
User::LeaveIfError(iListen.Open(iSocketServer, KAfInet,KSockStream, KProtocolInetTcp));
// Add self to active scheduler
CActiveScheduler::Add(this);
}
// Constructor and destructor
CServer::CServer(TInt aPriority/*,MServerObserver& aNotify*/)
: CActive(aPriority)/*,iNotify(aNotify)*/
{}
CServer::~CServer(){
if(IsAdded()){
Deque(); // calls also Cancel()
}
}
void CServer::DoCancel(){
Reset();
iSocketServer.Close();
iListen.Close();
iSocket.Close();
}
void CServer::DoAsyncAction(/*MServerObserver& aOberserver*/){
//__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive));
//__ASSERT_ALWAYS(_Observer, User::Panic(KMyActivePanic, ENoObserver));
iState=EStartSystem;
//iObserver->ToState( ELookingUpIP );
SetActive(); // Starting the active sheduler?
}
//active sheduler
void CServer::RunL(){
// add a bit of error checking
User::LeaveIfError(iStatus.Int()); // handle error in RunError (Whatever that means)
switch(iState){
case EStartSystem:{
if(iState == KErrNone){
Connect();
SetActive();
}else{
//iObserver->Cancelled( iMsgBuf );
Reset();
}
break;
}
case EConnecting:{
if(iState == KErrNone){
iState = EWriting;
//iObserver->ToState( EWriting );
TBuf8<255> data;
data.Append('b');
data.Append('l');
data.Append('u');
data.Append('b');
data.Append('b');
data.Append('\n');
iSocket.Send(data, 0, iStatus);
SetActive();
}else{
//iObserver->Cancelled( iMsgBuf );
Reset();
}
break;
}
}
// error condition
//iObserver->HandleRequestCompleted(KErrNone);
//SetActive();
}
void CServer::Connect(){
iState = EConnecting;
//iObserver->ToState( EConnecting );
/* The second (blank) socket is required to
build the connection & transfer data.
Bind the listening socket to the required
port.*/
iAddr.SetAddress(INET_ADDR(127,0,0,1));
iAddr.SetPort(4949);
User::LeaveIfError(iListen.Bind(iAddr));
// Listen for 2 incoming connections...
iListen.Listen(2);
User::LeaveIfError(iSocket.Open(iSocketServer));
// and accept an incoming connection.
// On connection, subsequent data transfer will
// occur using the socket iSocket
iListen.Accept(iSocket, iStatus);
}
void CServer::Reset(){
switch (iState)
{
case EConnecting:
iSocketServer.Close();
iListen.CancelAll();
iListen.Close();
break;
}
iState = ENotConnected;
}
TInt CServer::RunError(TInt aError){
//iObserver->HandleRequestCompleted(aError);
return KErrNone;
}