Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vzex committed Feb 15, 2016
1 parent ac14c2d commit 5b92531
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
8 changes: 5 additions & 3 deletions pipe/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ func NewInnerServerWithRouteAndQuit(addr string, c chan *HelperInfo, route *rout

type InnerClient struct {
conn net.Conn
tbl map[byte]func()
}

func NewInnerClient(addr string, c chan *HelperInfo) *InnerClient {
client := &InnerClient{}
conn, err := net.DialTimeout("tcp", addr, 30*time.Second)
if err != nil {
log.Println(err.Error())
Expand Down Expand Up @@ -208,11 +206,15 @@ func NewInnerClient(addr string, c chan *HelperInfo) *InnerClient {
}
c <- &HelperInfo{conn, Shutdown, []byte{}}
}()
client := &InnerClient{}
client.conn = conn
client.tbl = make(map[byte]func())
return client
}

func (c *InnerClient) Send(cmd Cmd, info interface{}) (int, error) {
return Send(c.conn, cmd, info)
}

func NewAdminHanderTbl() map[string]cmdHandler {
return make(map[string]cmdHandler)
}
Expand Down
11 changes: 6 additions & 5 deletions pipe/msg.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package pipe
import "time"

const (
//server spec cmd
Invalid Cmd = iota
Shutdown //自身服务关闭
Enter //远程连入
Leave //远程连出
Request
Response
)

type Action byte

//server common cmd
type CommonErrMsgCmd struct {
type RequestCmd struct {
Id uint64
AccountName string
Msg string
Action Action
Cmd string
OverTime time.Time
}
20 changes: 20 additions & 0 deletions remote/init.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package remote
import "flag"
import "log"
import "../pipe"

var service = flag.String("service", "", "")
var groupName = flag.String("group", "", "")
var nickName = flag.String("nick", "", "")
func Init() {
flag.Parse()
println("remote init")
c:=make(chan *pipe.HelperInfo)
go func() {
for {
select {
case info:=<-c:
switch info.Cmd {
case pipe.Request:
log.Println("request")
case pipe.Response:
log.Println("response")
}
}
}
}()
client := pipe.NewInnerClient(*service, c)
if client!=nil {
client.Send(pipe.Request, "haha")
}
}
9 changes: 9 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import "../pipe"
import "log"
func Listen(addr string) {
c := make(chan *pipe.HelperInfo)
go func() {
Expand All @@ -9,7 +10,15 @@ func Listen(addr string) {
case info := <-c:
switch info.Cmd {
case pipe.Leave:
log.Println("leave", info.Conn.RemoteAddr().String())
case pipe.Enter:
log.Println("enter", info.Conn.RemoteAddr().String())
case pipe.Request:
var s string
pipe.DecodeBytes(info.Bytes, &s)
log.Println("request", s)
case pipe.Response:
log.Println("response")
}
}
}
Expand Down

0 comments on commit 5b92531

Please sign in to comment.