Skip to content

Commit

Permalink
modify main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
hesh915 committed Sep 7, 2015
1 parent 879b7d8 commit b250787
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 20 deletions.
31 changes: 11 additions & 20 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package main

import (
"bufio"
"github.com/zhouhui8915/go-socket.io-client"
"log"
"bufio"
"os"
"time"
)

func main() {

opts := &socketio_client.Options{
Transport:"websocket",
Query:make(map[string]string),
Transport: "websocket",
Query: make(map[string]string),
}
opts.Query["uid"] = "1"
opts.Query["cid"] = "conf_123"
opts.Query["user"] = "user"
opts.Query["pwd"] = "pass"
uri := "http://192.168.1.70:9090/socket.io/"

client,err := socketio_client.NewClient(uri,opts)
client, err := socketio_client.NewClient(uri, opts)
if err != nil {
log.Printf("NewClient error:%v\n",err)
log.Printf("NewClient error:%v\n", err)
return
}

Expand All @@ -37,19 +36,11 @@ func main() {
log.Printf("on disconnect\n")
})

go func() {
authStr := "{\"uid\":\"" + opts.Query["uid"] + "\",\"cid\":\"" + opts.Query["cid"] + "\"}"
for {
client.Emit("authenticate", authStr)
time.Sleep(10 * time.Second)
}
}()

reader := bufio.NewReader(os.Stdin)
for {
for {
data, _, _ := reader.ReadLine()
command := string(data)
client.Emit("message",command)
log.Printf("send message:%v\n",command)
client.Emit("message", command)
log.Printf("send message:%v\n", command)
}
}
}
55 changes: 55 additions & 0 deletions example/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"github.com/zhouhui8915/go-socket.io-client"
"log"
"bufio"
"os"
"time"
)

func main() {

opts := &socketio_client.Options{
Transport:"websocket",
Query:make(map[string]string),
}
opts.Query["uid"] = "1"
opts.Query["cid"] = "conf_123"
uri := "http://192.168.1.70:9090/socket.io/"

client,err := socketio_client.NewClient(uri,opts)
if err != nil {
log.Printf("NewClient error:%v\n",err)
return
}

client.On("error", func() {
log.Printf("on error\n")
})
client.On("connection", func() {
log.Printf("on connect\n")
})
client.On("message", func(msg string) {
log.Printf("on message:%v\n", msg)
})
client.On("disconnection", func() {
log.Printf("on disconnect\n")
})

go func() {
authStr := "{\"uid\":\"" + opts.Query["uid"] + "\",\"cid\":\"" + opts.Query["cid"] + "\"}"
for {
client.Emit("authenticate", authStr)
time.Sleep(10 * time.Second)
}
}()

reader := bufio.NewReader(os.Stdin)
for {
data, _, _ := reader.ReadLine()
command := string(data)
client.Emit("message",command)
log.Printf("send message:%v\n",command)
}
}

0 comments on commit b250787

Please sign in to comment.