Skip to content
/ tim Public

Tiny portable instant messenger for the terminal.

License

Notifications You must be signed in to change notification settings

catsocks/tim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tim

A tiny instant messenger (tim) for the terminal in a single C file that I made as an exercise to learn more about network sockets and terminal emulators, meant to run with most terminal emulators on most recent Linux and BSD systems.

Usage

Tiny instant messenger

Usage:
    tim -l
    tim -c localhost -n ferris
    tim -L [::1]:8000 -y
    tim -c [::1]:8000 -n ferris

Options:
    -l       Listen for a connection at any IPv4 address
    -L ADDR  Listen for a connection at a specific address
    -c ADDR  Open a connection to an address
    -n NICK  Change your default nickname
    -y       Assume yes when asked to start a conversation
    -h       Show this message

By default tim will listen for a connection on any IPv4 address at port 7171, and use your username as your nickname unless you change it:

$ tim -l -n gopher
tim: Talk to "ferris" from 127.0.0.1? [y/N]: y
tim: You are now talking to ferris
ferris: Hi!
gopher: Bye!
tim: You ended the conversation

Connect to a listening tim instance to start a conversation:

$ tim -c 127.0.0.1 -n ferris
tim: You are now talking to gopher
ferris: Hi!
gopher: Bye!
tim: ferris ended the conversation

You will be informed of unacknowledged messages if any remains before the program exits:

tim: Your last 1 message(s) may not have been sent

Note that IPv6 addresses must be enclosed with square brackets per RFC 2732, and that the port you choose to use to listen for connections might need to be forwarded to your computer in your router so that incoming connections from outside your local network may reach the program.

Build

The only requirement is a Linux or BSD system with a compiler that supports the C99 standard (or newer) with GNU extensions. Simply feed tim.c into your preferred compiler or simply run the build.sh shell script.

Protocol

The protocol is inspired by the IRC protocol and it is made up of 7 simple plain text messages meant to fit a 1kb buffer:

  • NICK <nickname> Send nickname and request or accept a conversation
  • BUSY Decline a conversation
  • MSG <msg id> <msg body> Send a chat message
  • ACK <msg id> Acknowledge a received chat message
  • PING Ask for PONG message to test that an idle connection is still open
  • PONG Answer a PING message
  • QUIT Quit a conversation

TODO

  • Minimize global state, improve error handling and do away with atexit
  • Add tests
  • Encrypt messages
  • Support more ANSI control sequences for better message text editing

License

This project is dedicated to the public domain under the CC0 1.0 Universal license.

Resources