I have an application that transfers image from a mobile phone to a nearby PC with a special server through Bluetooth. It works fine in most cases, but sometimes if the picture is large or if there are a lot of Bluetooth traffic the phone crashes.

The screen slowly fades out and the phone restarts. However, when it restarts you do not need to type in your password again. The error happens on Nokia 6680, 7610 , 6630.

I would appreciate any suggestions or ideas.

/ Thomas

// The code that connects the device to the PC.
void CBluetoothClient::ConnectToServerL(const TBTDevAddr& aBTDevAddr, const TInt aPort)
{
iState = EConnecting;
Observer.InfoMessage(_L("Connecting to Service"));
iSocketAddress.SetBTAddr(aBTDevAddr);
iSocketAddress.SetPort(aPort);
User::LeaveIfError(iSendingSocket.Open(*iSocketServer,
KServerTransportName));
iSendingSocket.Connect(iSocketAddress, iStatus);
SetActive();
}

// A part of RunL()
case ESendingImgLength:
{
User::After(500);
iState=ESendingImgLength;
iTimer->After(iTimeOut);
TInt rest = iMessage->Size() - iWritePos;
TInt len = KWriteBufferSize;
if (rest<len)
{
len=rest;
iState=ESendingImgData;
}
TPtrC8 data = iMessage->Mid(iWritePos,len);
iWritePos+=len;
iSocket.Write(data, iStatus);
SetActive();
break;
}