精华内容
下载资源
问答
  • and this is where the request returns the error: WebSocket connection to 'wss://[URL]:4433/projects/socket' failed: WebSocket opening handshake was canceled. Binding the socket to 0.0.0.0 results in ...

    I have recently setup an EC2 instance (in a VPC with no load balancer) and admittedly the configuration is a bit odd, but it is what is required for the web application we're running.

    The web server (in Haskell) is running on port 4433 (standard ports are reserved for an Apache instance) and is receiving UDP packets being broadcast from another system. I have many of the ports wide-open (just during testing) as shown here (from Security Groups):

    Custom TCP Rule 4433 tcp 0.0.0.0/0 ✔

    Custom TCP Rule 8080 tcp 0.0.0.0/0 ✔

    SSH 22 tcp 0.0.0.0/0 ✔

    HTTP 80 tcp 0.0.0.0/0 ✔

    HTTPS 443 tcp 0.0.0.0/0 ✔

    Custom UDP Rule 30090 udp 0.0.0.0/0 ✔

    Custom UDP Rule 30089 udp 0.0.0.0/0 ✔

    The JavaScript for the TCP socket makes a request to setup the socket on this same port (using the URL assigned to the AWS's public IP) and this is where the request returns the error:

    WebSocket connection to 'wss://[URL]:4433/projects/socket' failed: WebSocket opening handshake was canceled.

    Binding the socket to 0.0.0.0 results in the same error.

    In order to start the Haskell web server I had to reference the internal IP provided by AWS as it would not run when referencing the public IP provided by the elastic IP service. Thinking this is where the problem came in I changed my socket request to this...

    wss://[internal ip]:4433/projects/socket

    This changes the error:

    WebSocket connection to 'wss://[internal IP]:4433/projects/socket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

    That error makes sense to me as the internal IP is not available to the outside world.

    Everything that I've read on websockets on AWS involves an ELB (Elastic Load Balancer) and I am not in need of one of those. I have tried all of the things in all of the currently posted answers (some of the questions haven't even gotten answers) on SO to no avail. I also setup a support case with Amazon (nearly 24 hours ago) which hasn't received a response.

    Additional Info

    Navigating to http://[URL]:4433/projects/socket yields 'WebSocket Available' where the URL is the one we wish to use as well as the Public DNS provided by AWS.

    Running netstat -plunt reveals the following:

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -

    tcp 0 0 [internal IP]:8080 0.0.0.0:* LISTEN -

    tcp 0 0 [internal IP]:4433 0.0.0.0:* LISTEN -

    tcp6 0 0 :::22 :::* LISTEN -

    tcp6 0 0 :::443 :::* LISTEN -

    tcp6 0 0 :::80 :::* LISTEN -

    udp 0 0 [internal IP]:30089 0.0.0.0:* -

    udp 0 0 0.0.0.0:30090 0.0.0.0:* -

    udp 0 0 0.0.0.0:11950 0.0.0.0:* -

    udp 0 0 0.0.0.0:68 0.0.0.0:* -

    udp6 0 0 :::38450 :::* -

    Has anyone had a similar problem with websockets on AWS? If so, how did you solve the problem?

    解决方案

    There was an SSL certificate mismatch between the Haskell server and the Apache server.

    The Haskell server had to be rebuilt with information concerning the new certificates for the instance. Further complicating this the proper SSL library (libssl0.9.8 libssl-dev) was not installed on the EC2 instance which was causing me problems during the rebuild of the Haskell server. Knowing an EC2 instance is a "blank canvas" makes the lack of that installation my fault.

    Once I had the libssl installed I was able to rebuild the Haskell server with it pointing to the new certificates. Once the certificates "matched" the websocket issue disappeared.

    Just to reiterate, ours is a unique situation. We have an Apache server (ports 80 and 443) and a Haskell server (ports 8080 and 4433) which communicate with each other, performing a pub-sub operation over websockets. A certificate mismatch between the two servers (it would not have mattered what type, it could have been multiple Apache instances) caused an SSL warning. Any warning from SSL will tear-down any attempt to establish or maintain a websocket (hence the handshake canceled message).

    Another StackOverflow post provided some clues that were of tremendous help during this process. More specifically this warning -

    The key to the problem is this: If your SSL certificate causes a warning of any sort, wss:// WebSocket connections will immediately fail, and there is no canonical way to detect this.

    展开全文
  • 我写的websocket 使用的是net core 2.2写的,一开始的时候报错说握手失败,直到后来看到别的大神说,初始化websocket的时候一定要在app.UseMvc之前执行,否则会被mvc 拦截,走不了自己实现的websocket请求处理,贴...

    今天写着个博客是为了大家早点跳出这个坑。我写的websocket 使用的是net core 2.2写的,一开始的时候报错说握手失败,直到后来看到别的大神说,初始化websocket的时候一定要在app.UseMvc之前执行,否则会被mvc 拦截,走不了自己实现的websocket请求处理,贴代码!

      #region 1.0 配置WebSocket 服务
    
        private void ConfigWebSocket(IApplicationBuilder app) {
    
            // Apis.mobile.MobileWebSocketHandle.AddWebSocket(app);
    
            WebSocketOptions options = new WebSocketOptions();
            options.KeepAliveInterval = TimeSpan.FromSeconds(120);
            options.ReceiveBufferSize = 4 * 1024;
            //options.AllowedOrigins.Add("http://127.0.0.1:8848");
            app.UseWebSockets(options);
            HandleWebSocket handle = new HandleWebSocket();
            app.Use(async (context, next) => {
                if (context.Request.Path != "/WebSocketService") {
                    await next();
                    return;
                }
                if (!context.WebSockets.IsWebSocketRequest) {
                    await next();
                    return;
                }
                WebSocket socket = await context.WebSockets.AcceptWebSocketAsync();
                await handle.AcceptAsync(context, socket);
            });
        } 
    
        #endregion
    

    配置的地方单独写了一个方法,需要在配置的地方setup的【ConfigureProduction/ConfigureDevelopment】或者【Configure】方法中调用,直接传过来app对象就可以了,使用的时候 其中的handleWebSocket类就不贴出来了,有需要的留言,handle类中主要工作就是处理浏览器端发来的请求。

    一切工作就绪之后就是部署到IIS上了,我用的服务器是2012 据说需要从2008开始才支持websocket,用2012妥妥的,部署的具体方法可以去看net core部署在IIS上的文章,网上一堆,下面说下需要注意的地方,在安装IIS的时候一定要把这个【websocket协议】勾上。

    在这里插入图片描述

    到此websocket就可以连接上了。

    转载自 wittdong

    展开全文
  • Websocket握手在Java失败

    2020-12-29 00:11:55
    之后,我尝试将客户机连接到服务器,并在onMessage方法中接收消息。WebSocketContainer container=ContainerProvider.getWebSocketContainer();Session Session=Container.ConnectToServer(ClientEndpoint.class,...

    之后,我尝试将客户机连接到服务器,并在onMessage方法中接收消息。

    WebSocketContainer container=ContainerProvider.getWebSocketContainer();Session Session=Container.ConnectToServer(ClientEndpoint.class,buildCEC(),new URI(“wss://async.example.com/socket.io/1/?t=”+System.currentTimeMillis());

    我尝试在buildCec()中插入到服务器连接的头。ClientEndpointConfig config=ClientEndpointConfig.Builder.Create()。Build();配置器conf=config.getConfigurator();`Map> headers = new HashMap>();

    headers.put("Connection", Arrays.asList("keep-alive", "Upgrade"));

    headers.put("Sec-Websocket-Extensions", Arrays.asList("x-webkit-deflate-frame"));

    headers.put("Sec-Websocket-key", Arrays.asList("cx36sHrtuW9HZAaB6kKa/Q=="));

    headers.put("Sec-Websocket-Version", Arrays.asList("13"));

    headers.put("Upgrade", Arrays.asList("websocket"));

    headers.put("User-Agent", Arrays.asList("Mozill..."));

    conf.beforeRequest(headers);

    return config;`

    问题如果我解决了这个问题并收到http升级请求的101个状态码,我的判断是否正确?(我的意思是,接下来我该如何处理这些细节?)

    请不要评判我,我刚开始使用Java的websockets,而且我不太了解javascript,我想用JSR-356在纯Java中做这个客户端。我已经用websockets做过一些小例子,但是我找不到一个好的客户端,它带有头和更复杂的握手。

    在不了解所有详细信息的情况下,是否可能连接到未知服务器?

    我使用一个编程端点并导入javax.websocket.ContainerProvider;用于处理来自JSR356的websocket连接。

    展开全文
  • 用swoole搭建的websocket服务器,经常会抛出 “ERROR zm_deactivate_swoole (ERROR 503): Fatal error: Uncaught ErrorException: swoole_http_client::push(): websocket handshake failed, cannot push data.” ...

    用swoole搭建的websocket服务器,经常会抛出 “ERROR zm_deactivate_swoole (ERROR 503): Fatal error: Uncaught ErrorException: swoole_http_client::push(): websocket handshake failed, cannot push data.” 异常。但是大部分时间还是可以连接上的。

    我的php版本是7.0.29,系统是CentOS 7.4.1708,swoole版本是 1.10.5

    我是在同一个服务器上,用swoole搭建的tcp服务中,通过:

    $cli = new \swoole_http_client('localhost', 9510);

    $cli->setHeaders([

    'UserAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'

    ]);

    $cli->on('message', function ($_cli, $frame) {

    });

    $cli->upgrade('/', function ($cli) use ($cabinetid, $param, $state, $head) {

    try {

    $ret = $cli->push($head . $cabinetid . $param . $state);

    if (!$ret) {

    $cli->push($head . $cabinetid . $param . $state);

    }

    } catch (Exception $exc) {

    $cli->push($head . $cabinetid . $param . $state);

    }

    });

    以上代码向 同一个服务器中的websocket服务发送消息的时候抛出的异常

    请问是什么原因?我该如何查找原因呢?

    展开全文
  • } } 就可连接成功,原因是:ServerEndpointExporter 会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint。如果使用独立的servlet容器,就不需要注入ServerEndpointExporter,因为它将由容器自己提供和...
  • This is the message I'm getting for my Wordpress site:"WebSocket connection to 'wss://public-api.wordpress.com/pinghub/wpcom/me/newest-note-data' failed: Error during WebSocket handshake: Unexpected r...
  • WebSocket握手总结

    2021-01-12 00:15:05
    1.概要WebSocket是最新提出用于实现服务器与浏览器双向通信的一种解决方案,用于取代一些传统的数据推送方案(如iframe长连接,ajax轮询等)。该方案由于一直在草案阶段,最新的版本为version 13.该版本出现在RFC6455...
  • WebSocket是一种先进的技术...首先,服务器必须使用标准TCP套接字监听传入的Socket连接。例如,假设您的服务器正在侦听http://example.com,端口80,并且您的套接字服务器响应GET请求/chat。服务器可能会侦听它选择...
  • 问题描述websocket连接失败后多久会触发error事件?这个时间有没有方法可以设置问题出现的环境背景最近项目中用到了websocket,但是连接地址的端口不确定,因此前端需要从某个端口(例如ws://127.0.0.1:9000)开始累加...
  •  b) websocket._exceptions.WebsocketBadStatusException: Handshake status 400  答:Access-Control-Allow-Origin 是HTML5中定义的一种服务器端返回Response header,用来解决资源(比如字体)的跨域权限问题。...
  • Nginx常规的代理转发配置是不支持websocket协议的。 本节主要介绍如何让Nginx代理支持websocket协议。 一、Nginx官网说明 Nginx对websocket协议的支持: http://nginx.org/en/docs/http/websocket.html location /...
  • websocket握手失败可能的原因之一

    千次阅读 2020-02-15 21:39:36
    server.servlet.context-path=/*** 如果在application.properties中配置了上面的属性,则在连接服务器时应该按照下面的链接进行连接,***是你配置的前缀 ...否则就会出现握手失败的错误。 在MyWeb...
  • websocket连接失败

    万次阅读 2015-06-26 23:31:21
    websocket连接失败@(markdown) 最近项目里调试websocket相关的nodejs实现的server,刚接触web开发的小伙伴们对websocket协议不熟悉,遇到问题很容易悲剧。这里只说自己理解的部分以及解决问题的经验吧。 首先,...
  • WebSocket 连接失败,报错400 WebSocket握手期间出错,响应码:400。 出现原因:可能你的应用程序版本低于nginx。 我的解决方式:告诉nginx在和服务端通信的时候,使用http/1.1,并且Nginx当想要使用WebSocket时由...
  • <p>"WebSocket connection to failed: Error during WebSocket handshake: Unexpected response code: 200" <p>This is my apache Configuration <pre><code>ServerName 192.168.56.106 ProxyRequests off ...
  • webSocket浏览器握手不成功(解决)

    千次阅读 2019-10-06 14:52:03
    websocket与服务端握手会报握手不成功的错误解决方法: 首先是服务端首次收到请求要回报给客户端的报文要做处理多的不说,方法敬上: 1 /// <summary> 2 /// 打包请求连接数据 3 /// </summary>...
  • 所以只能是web项目的问题,花了我四个小时,一点点看web项目的各个配置文件,最终发现是在设置跨域请求时,请求的allowedOrigins没有设置为*,导致连接失败。原因是websocket通讯的建立阶段是依赖于http协议的。最初...
  • 用java实现的websocket 我在不适用其他框架的时候可以正常握手访问 但是最近加在一个适用spring的项目中,一直握手不成功,这是什么原因? 以下是浏览器返回的信息 ``` Request URL:ws://127.0.0.1:8080/spring...
  • 在控制台中显示错误:WebSocket连接到'ws://localhost/socket/php-socket.php/wss'失败:期间出错$newSocket = socket_accept($socketResource);$clientSocketArray[] = $newSocket;$header = socket_read($newSocket,...
  • <p>I found <a href="http://procbits.com/connecting-to-a-sockjs-server-from-native-html5-websocket" rel="nofollow">this article</a> referring to node.js indicating to add /websocket to my client ...
  • WebSocket握手期间出错:意外的响应代码:500我在我的网站上使用websocket,但随机发送给我以下错误消息:WebSocket连接到'ws://client.mydomain....WebSocket握手期间出错:意外的响应代码:500这里是我...
  • 但是一部署到生产服务器上,Web端只要一new WebSocket(url),就返回握手失败404。各种方法都试过了,全部无效。 什么改nginx的Upgrade升级啦(这个是必须改的),注释掉WebsocketConfig类中的Bean啦(我压根就没建...
  • 我在连接到套接字服务器时遇到问题。WebSocket connection to failed: Error during WebSocket handshake: Unexpected response code: 521我有两个不同的云服务器(1)用于客户端项目,(2)用于套接字服务器。(1)客户...
  • 2016-02-16 15:23:490You can find the all the code below,started the tomcat server and It's perfectly working.But While making websocket request I'm getting 404 error.This is the error in chrome consol...
  • 这是chrome控制台中的错误:WebSocket连接到&#39; ws:// localhost:8088 / websocket-example / websocket&#39;失败:WebSocket握手期间出错:意外的响应代码:404并且没有服务器日志。Java WebSoc...
  • WebSocket无法连接问题

    千次阅读 2021-10-21 10:48:42
    rosbridge连接不稳定问题 问题描述: Windows端web连接Ubuntu端rosbridge server,出现有时能连上有时连不上的问题。 最近一次发生连接不上的情况是,前一天可以连接成功,第二天,重新启动rosbridge server,从...
  • java websocket连接404

    千次阅读 2018-03-14 03:35:42
    1.注意javaee.jar包是否有webSocket相关类,如果有就不用引入这个包了。2.访问路径:ws://ip:端口/项目名/ServerEndpoint设置的...无法连接websocketError during WebSocket handshake: Unexpected response code: 4...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,669
精华内容 1,867
热门标签
关键字:

websocket连接握手失败

友情链接: SignatureSpi.rar