Permalink
Browse files

using log instead of fmt

  • Loading branch information...
1 parent d7e6c36 commit da53e599611785a85bec2c47a7fdb09545f47865 @kicool committed Apr 11, 2012
Showing with 15 additions and 8 deletions.
  1. +2 −1 README
  2. +9 −5 echo.cs/client.go
  3. +4 −2 echo.cs/server.go
View
3 README
@@ -1,9 +1,10 @@
-5 samples:
+samples:
hello
echo
sum
math
alloc
+ cgo
*.Binary file compare
Linux svr-ubuntu-mirror 2.6.35-22-server #35-Ubuntu SMP Sat Oct 16 22:02:33 UTC 2010 x86_64 GNU/Linux
View
@@ -3,27 +3,31 @@ package main
// Connect to JSONRPC Server and send command-line args to Echo
import (
- "fmt"
+ "flag"
+ "log"
"net"
"net/rpc/jsonrpc"
"os"
- "flag"
)
var destAddr = flag.String("d", "127.0.0.1:1234", "server addr")
var message = flag.String("m", "", "message send to server")
func main() {
flag.Parse()
+ log.SetPrefix("echo.client: ")
conn, e := net.Dial("tcp", *destAddr)
if e != nil {
- fmt.Fprintf(os.Stderr, "Could not connect: %s\n", e)
+ log.Fatalf("Could not connect: %s\n", e)
os.Exit(1)
}
+
client := jsonrpc.NewClient(conn)
+
var reply string
- fmt.Printf("Sending: %s\n", *message)
+
+ log.Println("Sending:", *message)
client.Call("RPCFunc.Echo", *message, &reply)
- fmt.Printf("Reply: %s\n", reply)
+ log.Println("Reply :", reply)
}
View
@@ -1,11 +1,11 @@
package main
import (
+ "flag"
"log"
"net"
"net/rpc"
"net/rpc/jsonrpc"
- "flag"
)
var addr = flag.String("i", "127.0.0.1:1234", "listen address and port")
@@ -20,6 +20,7 @@ func (*RPCFunc) Echo(arg *string, result *string) error {
func main() {
flag.Parse()
+ log.SetPrefix("echo.server: ")
log.Print("Starting Server...")
l, err := net.Listen("tcp", *addr)
@@ -28,12 +29,13 @@ func main() {
log.Fatal(err)
}
log.Print("listening on: ", l.Addr())
+
rpc.Register(new(RPCFunc))
for {
log.Print("waiting for connections ...")
conn, err := l.Accept()
if err != nil {
- log.Printf("accept error: %s", conn)
+ log.Fatal("accept error:", conn, err)
continue
}
log.Print("connection started:", conn.LocalAddr(), conn.RemoteAddr())

0 comments on commit da53e59

Please sign in to comment.