Sonsivri

Electronics => Projects => Topic started by: puta on May 13, 2017, 01:51:48 01:51



Title: TCP / UDP socket programming for Raspberry PI
Post by: puta on May 13, 2017, 01:51:48 01:51

I am doing experiments for a project that need to develop a telnet server on the Raspberry pi, and to provide remote cli access (via telnet client) to read various status of the PI.

Could someone point me to a good document on the TCP / UDP socket programming for Raspberry PI.

Thanks heaps for help !
 


Title: Re: TCP / UDP socket programming for Raspberry PI
Post by: adamantium on May 14, 2017, 03:36:49 15:36
Hi puta,

It really depends on what programming languages you're familiar with, after all, Raspberry Pi's are just running ARM linux. Do you want to provide a telnet like server, with custom commands to read some statuses? Or do you want to provide actual shell command line access?

If the former, the easiest would be to just use python or javascript.

For example, if you're familiar with javascript load nodejs on the pi, create a project and use an npm dependency 'telnet' (https://www.npmjs.com/package/telnet), which lets you create a server that implements the Telnet protocol.

You can then use a callback function to listen for commands that the client sends, and respond accordingly.


Title: Re: TCP / UDP socket programming for Raspberry PI
Post by: puta on May 15, 2017, 04:23:40 04:23

Thanks Adamantium, it is the former, using python or javascript or other.

What i need is to implement telnet server on a none-standard tcp port ( other than standard port tcp/23), and implement functions/procedures to service various statuses ( simple eg, status of a port, or a value read on a spi bus) so that remote client can enter specific commands to execute functions/procedures on the server and read statuses.   


Title: Re: TCP / UDP socket programming for Raspberry PI
Post by: adamantium on May 15, 2017, 06:26:16 06:26
Yep, you can do all that with node running on the pi. Use the telnet package I linked above, you can specify a port for it to listen on.

For reading port status you can use https://www.npmjs.com/package/rpi-gpio
And for communicating with SPI devices, https://www.npmjs.com/package/spi

I haven't used the telnet package personally, but I have used the gpio and spi ones in the past on a pi 2.


Title: Re: TCP / UDP socket programming for Raspberry PI
Post by: UKFlyer on July 20, 2017, 11:20:25 11:20
The book "Raspberry Pi IOT in C" has a good chapter on socket programming. Unfortunately the relevant chapter is not on the website but I've found the book worth buying.