I use golang write a test websocket server .
package main
import (
"code.google.com/p/go.net/websocket"
"fmt"
"log"
"net/http"
)
func Echo(ws *websocket.Conn) {
var err error
for {
var reply string
if err = websocket.Message.Receive(ws, &reply); err != nil {
fmt.Println("Can't receive")
break
}
fmt.Println("Received back from client: " + reply)
msg := "Received: " + reply
fmt.Println("Sending to client: " + msg)
if err = websocket.Message.Send(ws, msg); err != nil {
fmt.Println("Can't send")
break
}
}
}
func main() {
fmt.Println("begin")
http.Handle("/socket", websocket.Handler(Echo))
if err := http.ListenAndServe(":80", nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
fmt.Println("end")
}
I test in [[http://www.websocket.org/echo.html]], It’ work. and I use python write a simple websocket-client. It’s also work.
but I modify the testcpp/WebSocketTest.cpp line:80 “ws://echo.websocket.org” with “ws://localhost:80/socket”. The testcpp can’t work in win32 and android.
error code: CONNECTION_FAILURE
Anybody can tell me where is the problem.