I am new to Symbian C++ and I try to write a tcpip client to send data.
I also use java to write the server and run on the same computer.
I find some code on the web write it inside one file and like that but the emulator close after runing a while,
it seems fail in lSocket.Connect(lServSockAddr,status) and my Java Server doesn't get any client.
Does anyone can tell me what's wrong? Thank you very much!
This is all my code:
#include <e32cons.h>
#include <es_sock.h>
#include <in_sock.h>
// Function prototype
LOCAL_C void UseBasicTypesL();
//////////////////////////////////////////////////////////////////////////////
//
// Main function called by E32
//
//////////////////////////////////////////////////////////////////////////////
GLDEF_C TInt E32Main()
{
// Catch any Leaves thrown
TRAPD(error, UseBasicTypesL());
_LIT(KMsgPanic,"Error in Symbian OS Basics Lab: ");
__ASSERT_ALWAYS(!error, User::Panic(KMsgPanic, error));
return 0;
}
//////////////////////////////////////////////////////////////////////////////
LOCAL_C void UseBasicTypesL()
{
// Constant text used for the console app title
_LIT(KLabTitle,"Testing");
CConsoleBase* console = Console::NewL(KLabTitle, TSize(KConsFullScreen, KConsFullScreen));
TRequestStatus status;
RSocketServ lSession;
RSocket lListenSocket, lSocket;
TInt lErr;
// Connect to the socket server
lErr=lSession.Connect();
User::LeaveIfError(lErr);
lErr = lListenSocket.Open(lSession,KAfInet, KSockStream,KProtocolInetTcp);
User::LeaveIfError(lErr);
TInetAddr lServSockAddr;
const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
lServSockAddr.SetAddress(KInetAddr);
lServSockAddr.SetPort(5888);
lSocket.Connect(lServSockAddr,status); // it seems fail at here when I use debug mode
const TText8* txt = (TText8*)_S("My Tcpip client test");
TBuf8<100> sbuf(txt);
lSocket.Send(sbuf, 0, status));
TBuf8<100> rbuf;
TSockXfrLength aLen;
lSocket.RecvOneOrMore(rbuf,0,status, aLen);
console->Printf(_L("Received Data is:: "),rbuf);
// Continue
_LIT(KMsgPressAnyKey,"Press any key to end");
console->Printf(KMsgPressAnyKey);
console->Getch();
delete console;
}




