#204·ws

report tls: first record does not look like a TLS handshake when dial with tls option

Author: mebest100Created Oct 1, 2024Updated Oct 2, 2024

Hi, it report "tls: first record does not look like a TLS handshake" when dial with tls option

And the code is as follows:

	dialer := ws.Dialer{
		Header: ws.HandshakeHeaderHTTP(header), 
		NetDial: func(ctx context.Context, network, addr string) (net.Conn, error) {
			
			rawConn, err := net.Dial(network, addr)
			if err != nil {
				log.Logf("websocket dial tcp fail, err==> %v", err)
				return nil, err
			}
		
			tlsConn := tls.Client(rawConn, tlsConfig)
			return tlsConn, nil
		},
	}

	
	conn, _, _, err := dialer.Dial(context.Background(), url)

the tlsConfig is generated by self-signed , but the same config work well with gorilla/websocket lib. Pls kindly advise the probal causes and solutions. Thx!