How to enable adbd to listen to a port at boot time in Android? I have a rooted HTC Hero, and what I want to do is to enable the adbd
to listen to a port at boot time.

I tried some code found here:

setprop service.adb.tcp.port 5555
stop adbd
start adbd


in an Android shell and it works great.

I tried to change the init.rc file. I added the above code in init.rc
and I replaced it with the original file, through these commands:

adb push init.rc sdcard

adb shell
adb su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /
adb cp sdcard/init.rc /


The file is replaced successfully, but when I reboot my phone and try to connect
through:

adb connect &lt;IP&gt;:5555


the connection is not being established.

Any ideas?

(PS. I don't want to use the remoteADB application and a shell command like
    am start -n ...
)
The reason it does not work properly is this:
The init.rc script resides in within the RAMDisk attached to the boot image.
Hence the init.rc script that was edited and pushed across is now overwritten by the boot image's own script upon reboot - effectively changes are lost!
You need to extract the boot image, using every boot image has the kernel and the RAMDisk. The tools available to do this can be found here.
Extracting
When invoking the script split_bootimg.pl on a boot image it will recreate the following:

boot.kernel
boot.ramdisk.gz

The two files are obviously self-explanatory. To extract the ramdisk, create a directory called RAMDisk and from that directory, invoke this: gzip -dc | cpio -i, to recreate the directory structure that is used in the RAMDisk which gets flipped over to the live file-system upon boot. In there, the file that is of pertinent information is init.rc. Now that can be modified to your heart's content.
Putting it back together
Go back up a directory level, and issue this - mkbootfs ***RAMDisk*** | gzip &gt; my_custom_ramdisk.gz.
Then, to &quot;attach&quot; the original kernel to the boot image, issue the following: mkbootimg -base 0x.... -kernel boot.kernel -ramdisk my_custom_ramdisk.gz -o my_custom_boot.img.
At this point now, a boot image has been constructed, then that boot image will now have to be flashed via fastboot flash boot my_custom_boot.img.
TL;DR
Changes are lost upon re-boot because the script is not properly edited which required extracting the boot image and modifying it and re-packing it. Once re-packed and then the boot image is re-flashed, the changes will be permanent.
This is done every-time the changes are needed.