https://github.com/songgao/pingpong
pingpong is a utility commandline tool that makes testing server/client programs easier by interleaving output from different commands and labeling them with different colors.
https://github.com/songgao/pingpong
Last synced: 25 days ago
JSON representation
pingpong is a utility commandline tool that makes testing server/client programs easier by interleaving output from different commands and labeling them with different colors.
- Host: GitHub
- URL: https://github.com/songgao/pingpong
- Owner: songgao
- Created: 2013-05-28T01:54:17.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-06-11T23:21:08.000Z (almost 12 years ago)
- Last Synced: 2025-03-29T23:51:09.400Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 883 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pingpong
`pingpong` is a utility commandline tool that makes testing server/client programs easier by interleaving output from different commands and labeling them with different colors.
## Installation
```shell
$ go get -u github.com/songgao/pingpong
```## Usage
```
Usage: pingpong [OPTIONS] -- cmd1, cmd2, ...
-h=false: Print help message; an empty string means no logging
-help=false: Print help message; an empty string means no logging
-log="": Directory for logging
-time=true: Prepend time before each line
```
Each `cmd` is fed into `bash -c` to be executed.## Example
Here's a simple piece of code composed with server and clients:
```go
package mainimport (
"net"
"time"
"fmt"
"os"
"io"
"strconv"
)const STR = `Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.`
func main() {
switch os.Args[1] {
case "server": server()
case "client": client()
default:
}
}func server() {
ln, err := net.Listen("tcp", ":9090")
if err != nil{ return }
go func() {
flag := true
for {
conn, _ := ln.Accept()
if err != nil { continue }
fmt.Printf("-- Client connected: %s\n", conn.RemoteAddr())
fmt.Fprintln(conn, "Hello client, greetings from server!")
if flag {
fmt.Fprintf(conn, "%s\n", STR)
flag = false
}
go func() {
io.Copy(os.Stdout, conn)
fmt.Printf("-- Client disconnected: %s\n", conn.RemoteAddr())
}()
}
}()
time.Sleep(8 * time.Second)
}func client() {
id, _ := strconv.Atoi(os.Args[2])
time.Sleep(2 * time.Duration(id) * time.Second)
conn, err := net.Dial("tcp", "localhost:9090")
if err != nil { return }
go io.Copy(os.Stdout, conn)
fmt.Fprintf(conn, "Hello server, greetings from client %d!\n", id)
time.Sleep(time.Second)
conn.Close()
}
```Running 4 commands with `pingpong`:
```shell
$ pingpong -log="./logs" "go run main.go server" "go run main.go client 1" "go run main.go client 2" "exit 1"
```Screenshot:

## License
[BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)