コード例 #1
0
ファイル: server.go プロジェクト: desertbit/pakt
func foo(c *pakt.Context) (interface{}, error) {
	// Create a dummy value.
	data := struct {
		A, B string
		C    int
	}{}

	// Decode the received data from the peer to the dummy value.
	err := c.Decode(&data)
	if err != nil {
		// The remote peer would get this error.
		return nil, err
	}

	// Log.
	log.Printf("received data from client: %+v", data)

	// Just send the data back to the client.
	return data, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: desertbit/pakt
func bar(c *pakt.Context) (interface{}, error) {
	// Decode the received data from the peer to the dummy value.
	var data string
	err := c.Decode(&data)
	if err != nil {
		// The remote peer would get this error.
		return nil, err
	}

	// Log.
	log.Printf("received data from server: %+v", data)

	// Close the socket and exit the application after a short timeout.
	go func() {
		time.Sleep(500 * time.Millisecond)
		c.Socket().Close()
	}()

	// Just send the data back to the client.
	return data, nil
}