My guess is that you're using two SoftwareSerial instances and one of the many drawbacks this horrible piece of code has is that only one instance at a time can listen.
As you state that you're using a Mega why don't you use the available hardware serial interfaces (the Mega has 4 of them)?
pylon:
This is not your code as it doesn't compile.
I know selected just important in my code
pylon:
My guess is that you're using two SoftwareSerial instances and one of the many drawbacks this horrible piece of code has is that only one instance at a time can listen.
I already added in my code HC.listen(); & gsm.listen();
but Do not work efficiently , sometime HC receive Data some time don't.
I already added in my code HC.listen(); & gsm.listen();
but Do not work efficiently , sometime HC receive Data some time don't.
That's probably because they cannot listen at the same time even if you call the listen() methods. So while listen is active for the HC instance all characters that where sent by the GSM device are lost and vice-versa.
Did you read my last sentence in my first answer? Use the hardware serial interfaces and your problems are gone.