Using telnet in a C Program

后端 未结 5 386
情歌与酒
情歌与酒 2020-12-09 12:53

I am working on a robot automation project and I have run into a road block. To control the robot, one needs to connect with it wirelessly via telnet and send commands throu

相关标签:
5条回答
  • 2020-12-09 13:11

    Expect would allow you to interact with external programs, but I am not aware of a C port of expect. Otherwise you would find a telnet library in C or write your own using socket programming.

    0 讨论(0)
  • 2020-12-09 13:19

    You are looking for sockets. This is a comprehensive guide to socket programming in C. Telnet is also a well defined protocol, although I don't know if this robot would use telnet or not (it's extra processing overhead for a protocol that wouldn't have much added benefit for a robot control program). Telnet is covered in detail by RFC 854

    0 讨论(0)
  • 2020-12-09 13:22

    I would use libcurl: http://curl.haxx.se/libcurl/. It'll do what you want, and handle all the telnet goo that you really don't want to handle.

    0 讨论(0)
  • 2020-12-09 13:27

    I would be:

    • writing some simple shell scripts containing the telnet interractions written as here documents.
    • using a .telnetrc file in your home directory to control aspects of your telnet session, e.g. crmod
    • calling the script using system calls.

    This way your turnaround time to change your interractions with the robot won't involve having to recompile your programm all the time.

    BTW This sounds like fun.

    HTH.

    cheers,

    Rob

    0 讨论(0)
  • 2020-12-09 13:33

    Expect was designed to do exactly this - hold conversations with interactive programs. It's written in Tcl, extending the Tcl interpreter with various commands. Tcl is very easy to extend; it was designed to be an embedded scripting language right from the word go. The main C API uses argv-style constructs to pass parameters to Tcl commands and is very easy to use. The best guide to the C API is Ousterhout's original book and it took me one two-hour lab session to get my first embedded Tcl interpreter up and running.

    As a bonus you also get a built-in Tcl interpereter, which you can use to add a scripting capability to your application. You'll probably find that quite a bit of it can be implemented in Tcl if you feel so inclined, so it will probably save you time overall.

    0 讨论(0)
提交回复
热议问题