// creatBasicServer is a ruddy implementation of a redirect server. It's *really* basic and just serves as a conn forwarder.
creatBasicServer is a ruddy implementation of a redirect server. It's *really* basic and just serves as a conn forwarder.
// creatBasicServer is a ruddy implementation of a redirect server . It ' s * really * basic and just serves as a conn forwarder .
func creatBasicServer(t *testing.T) *http.ServeMux {
	upg := websocket.Upgrader{}
	pool := enfuse.NewPool(enfuse.DefaultPayloadStrategy)
	m := http.NewServeMux()
	m.HandleFunc("/client", func(writer http.ResponseWriter, request *http.Request) {
		webConn, err := upg.Upgrade(writer, request, nil)
		if err != nil {
			http.Error(writer, "internal test error", 500)
			return
		}
		for {
			m, t, err := webConn.ReadMessage()
			if err != nil {
				fmt.Println(err.Error())
				continue
			}
			if err := pool.WriteWebsocketServer(m, t, webConn); err != nil {
				fmt.Println(err.Error())
				continue
			}
		}
	})
	m.HandleFunc("/server", func(writer http.ResponseWriter, request *http.Request) {
		webConn, err := upg.Upgrade(writer, request, nil)
		if err != nil {
			http.Error(writer, "internal test error", 500)
			return
		}
		if err := pool.SetServer(webConn); err != nil {
			http.Error(writer, "server set err ", 500)
			return
		}
		for {
			t, payload, err := webConn.ReadMessage()
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			clientConn := pool.Fetch(payload)
			if clientConn != nil {
				if err := clientConn.WriteMessage(t, payload); err != nil {
					fmt.Println(err.Error())
					return
				}
			}
		}
	})
	return m
}
func creatBasicServer ( t * testing . T ) * http . ServeMux { upg := websocket . Upgrader { } pool := enfuse . NewPool ( enfuse . DefaultPayloadStrategy ) m := http . NewServeMux ( ) m . HandleFunc ( " " , func ( writer http . ResponseWriter , request * http . Request ) { webConn , err := upg . Upgrade ( writer , request , nil ) if err != nil { http . Error ( writer , " " , 500 ) return } for { m , t , err := webConn . ReadMessage ( ) if err != nil { fmt . Println ( err . Error ( ) ) continue } if err := pool . WriteWebsocketServer ( m , t , webConn ) ; err != nil { fmt . Println ( err . Error ( ) ) continue } } } ) m . HandleFunc ( " " , func ( writer http . ResponseWriter , request * http . Request ) { webConn , err := upg . Upgrade ( writer , request , nil ) if err != nil { http . Error ( writer , " " , 500 ) return } if err := pool . SetServer ( webConn ) ; err != nil { http . Error ( writer , " " , 500 ) return } for { t , payload , err := webConn . ReadMessage ( ) if err != nil { fmt . Println ( err . Error ( ) ) return } clientConn := pool . Fetch ( payload ) if clientConn != nil { if err := clientConn . WriteMessage ( t , payload ) ; err != nil { fmt . Println ( err . Error ( ) ) return } } } } ) return m }
creatBasicServer is a ruddy implementation of a redirect server.
creatBasicServer is a ruddy implementation of a redirect server .