Hi Everyone,

Server and client both are developed in go. I am using
*github.com/gorilla/websocket
<http://github.com/gorilla/websocket> *library to establish a web socket
connection.
My server is running on port 8080 as docker container and my client (cli
tool) is running as docker container in another host. When the client
requests the server with "WS://domain_name:8080/api/connect" to establish
ws connection, nothing is happening even an error also not occurred at both
ends. It is working good in localhost but when the server and client are
running as containers, it is not working as expected.

If anyone has any idea to solve this issue,please let me know.

Any help is appreciated. Thank you!!

Sample server code:
var upgrader = websocket.Upgrader{} // use default options
func echo(w http.ResponseWriter, r *http.Request) {
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("upgrade:", err)
return
}
defer c.Close()
for {
mt, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
break
}
log.Printf("recv: %s", message)
err = c.WriteMessage(mt, message)
if err != nil {
log.Println("write:", err)
break
}
}
}





Sample client code:

var addr = flag.String("addr", "localhost:8080", "http service address")
func main() {
flag.Parse()
log.SetFlags(0)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
u := url.URL{Scheme: "ws", Host: *addr, Path: "/echo"}
log.Printf("connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN1Sb7wnQHgotLADWdeKn7QT9hUP0frqML4zL4uT-H%3DMGkiLCQ%40mail.gmail.com.

Reply via email to