# Drawing network protocols

I want to produce network protocols, a very simplified example of which is depicted below:

The protocol has two parties, each of which does some computation and then communicated with the other.

I can use a 3-column table, but I want to know if there is any better solution. Especially, whether there is any particular package for this, or any simple way to do it in TikZ.

-
Don't you think the image is a little too sparse? Visually it doesn't convey the message that the time is going downwards. I think the arrows need to have a target and a source. Of course I have no idea what are the specific practices of your field but still it can be a little intuitive. – percusse May 1 '12 at 21:02

Here is my simple solution using the method shown here:

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains, calc}
\begin{document}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, nodes={draw=none, anchor=center,text depth=0pt} ]{
Prover & & Verifier\\[-4mm]
Choose a random number & & \\[-7mm]
$r \in \{0,1\}^{*}.$ & & \\
& Send $r$ & \\
& & Choose a random number  \\[-7mm]
& &$s \in \{0,1\}^{*}.$\\
& Send $s$ & \\
};

\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-1.south east)--(m-1-1.south west);
\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-3.south east)--(m-1-3.south west);
\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-4-2.south west)--(m-4-2.south east);
\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-7-2.south east)--(m-7-2.south west);
\end{tikzpicture}
\end{document}


EDIT The graphical result is:

-
It's always nice to have an image of the result. The standalone class or pdfcrop can help here. It is recommended to convert it to a PNG yourself before uploading. You can use \documentclass[png]{standalone} and then compile with pdflatex -shell-escape (needs Image Magic to be installed). – Martin Scharrer May 1 '12 at 20:35

Did you look at MSC (Message Sequence Charts) package in CTAN? I've never used but some of our students did it. I think it needs LaTeX not pdflatex.

EDIT Your example could be done with some code like this

\documentclass[border=2mm]{standalone}
\usepackage{msc}
\begin{document}
\begin{msc}{Example}
\declinst{prover}{}{Prover}
\declinst{verifier}{}{Verifier}
\action*{%
\begin{minipage}{3cm}\centering
Choose a random number\\
$r\in\{0,1\}^*$
\end{minipage}%
}{prover}
\nextlevel[4]
\mess{Send $r$}{prover}{verifier}
\nextlevel
\action*{%
\begin{minipage}{3cm}\centering
Choose a random number\\
$r\in\{0,1\}^*$
\end{minipage}}{verifier}
\nextlevel[4]
\mess{Send $s$}{verifier}{prover}
\end{msc}
\end{document}


and the result (with xelatex because msc uses pstricks) is

The apperance is not so flexible because msc diagrams are normalized by ITU (International Telecomunication Union) and the package respects the format.

-