Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikif70 committed Mar 13, 2015
1 parent 46ced13 commit 53662e1
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions rlisten.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,42 @@
package main

import (
"flag"
"fmt"
"net"
"os"
)

type Config struct {
wrapUrl string
ssdbUrl string
wrapAddr *net.TCPAddr
ssdbAddr *net.TCPAddr
}

var (
config = &Config{
wrapUrl: "0.0.0.0:6380",
ssdbUrl: "10.39.80.181:8888",
}
)

func parseCmd([]byte) {

}

func init() {
flag.StringVar(&config.ssdbUrl, "s", config.ssdbUrl, "ssdb ip:port")
flag.StringVar(&config.wrapUrl, "l", config.wrapUrl, "listen ip:port")
}

func main() {
addr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:6380")
fmt.Printf("Listen: %+v\n", addr)
ln, err := net.ListenTCP("tcp", addr)
flag.Parse()

config.ssdbAddr, _ = net.ResolveTCPAddr("tcp", config.ssdbUrl)
config.wrapAddr, _ = net.ResolveTCPAddr("tcp", config.wrapUrl)
fmt.Printf("Listen: %+v\n", config.wrapAddr)
ln, err := net.ListenTCP("tcp", config.wrapAddr)
if err != nil {
fmt.Println("Listen err: ", err.Error())
return
Expand Down Expand Up @@ -40,12 +67,13 @@ func main() {
return
}

parseCmd(buf[:nr])

file.Write(buf[:nr])
file.Write([]byte("++++++++\n\r"))
fmt.Printf("Read: %d - %v\n", nr, string(buf[:nr]))
fmt.Printf("Read %d bytes:\n%v++++++++\n", nr, string(buf[:nr]))

ssdbAddr, _ := net.ResolveTCPAddr("tcp", "10.39.80.181:8888")
ssdb, err := net.DialTCP("tcp", nil, ssdbAddr)
ssdb, err := net.DialTCP("tcp", nil, config.ssdbAddr)
if err != nil {
fmt.Println("Dial err: ", err.Error())
return
Expand All @@ -62,7 +90,7 @@ func main() {
}

conn.Write(buf[:nr])
fmt.Printf("Reply: %d - %v\n", nr, string(buf[:nr]))
fmt.Printf("Reply %d bytes:\n%v--------\n\n", nr, string(buf[:nr]))
file.Write(buf[:nr])
file.Write([]byte("--------\n\r"))

Expand Down

0 comments on commit 53662e1

Please sign in to comment.