Websocket服务器出现RSA_padding_check_PKCS1_type_2错误

我想从我的SSL网站向我的php-websocket服务器发送消息。 服务器使用通配符证书。</ p>

这是客户端:</ p>

  var wsUri =“wss://ticket.qwellcode.de  :9001“; 
websocket_qcode_intern = new WebSocket(wsUri);
</ code> </ pre>

这是我的Websocket服务器:</ p>

   $ socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);

socket_set_option($ socket,SOL_SOCKET,SO_REUSEADDR,1);
socket_bind($ socket,0,$ port);

socket_listen($ socket);
...
</ code> </ pre>

要解密消息(例如标题),我使用以下代码:</ p>

  function decryptString($ cryptText)
{
$ keyFile = fopen(“PATH / TO / pemfile.pem”,“r”)或die(“NOT FOUND”);
$ privateKey = fread($ keyFile,8192);
fclose($ keyFile);

openssl_get_privatekey($ privateKey);
$ binText = base64_decode($ cryptText);

/ *不使用此PADDING * /
// openssl_private_decrypt($ binText,$ clearText,$ privateKey,OPENSSL_PKCS1_PADDING);
openssl_private_decrypt($ binText,$ clearText,$ privateKey);
print openssl_error_string();
return($ clearText); \ n}
</ code> </ pre>

问题是填充“OPENSSL_PKCS1_PADDING”(或其他填充)我得到以下消息:</ p>

 错误:0407106B:rsa例程:RSA_padding_check_PKCS1_type_2:block 
type不是02
</ code> </ pre>

使用选项“OPENSSL_NO_PADDING”我得到这样的废话解码代码: </ p>

 ▬♥☺☺☺  ù♥☻→ª↕FROMTý¤▬3Åμ▬g»►F↕Ñ;nÏágdCH╝*└
└└!└¶└↕└└◄32 E 98ê▬/ A5ä
♣♦☺ D↑▬!domain.de☺☺
♠↨↑♂♂☻☺#3t♣♣☺
</ code> </ pre>

我使用SSL-Zetificat加密, PKCS#1 SHA-1 - 带有SHA 1的AES 128 CBC。</ p>

如何解密此代码? ...我尝试了一切......是的,我知道,我可以使用流套接字..但我会用“普通”的php-socket解决这个问题... </ p>

为什么 我在解密时遇到了麻烦吗? 有解决方案吗? </ p>
</ div>

展开原文

原文

I want to send a message from my SSL Website to my php-websocket server. The server uses a wildcard certificate.

This is the client:

var wsUri = "wss://ticket.qwellcode.de:9001";
websocket_qcode_intern = new WebSocket(wsUri);

And this my Websocket server:

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);    
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, 0, $port);    
socket_listen($socket);
...

To decrypt a message (e.g the header) I use the following code:

function decryptString($cryptText)
{
    $keyFile=fopen("PATH/TO/pemfile.pem","r") or die("NOT FOUND");
    $privateKey=fread($keyFile,8192);
    fclose($keyFile);

    openssl_get_privatekey($privateKey);
    $binText = base64_decode($cryptText);

    /* NOT WORK WITH THIS PADDING */
    //openssl_private_decrypt($binText,$clearText,$privateKey,OPENSSL_PKCS1_PADDING);
    openssl_private_decrypt($binText,$clearText,$privateKey);
    print openssl_error_string();
    return($clearText);
}

The problem is that with the padding "OPENSSL_PKCS1_PADDING" (or other paddings) I get the following message:

error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block
type is not 02

With the option "OPENSSL_NO_PADDING" I get crap decoded code like this:

▬♥☺ ø☺  ù♥☻→ª   ↕ FRomTý¤▬3ŵ▬g»►F↕Ñ;nÏágdCH╝  *└
└       └‼└¶└↕└└◄ 3 2 E 9 8 ê ▬ / A 5 ä
 ♣ ♦☺  D   ↑ ▬  ‼domain.de ☺ ☺
 ♠ ↨ ↑ ↓ ♂ ☻☺  #  3t   ♣ ♣☺

I Use a SSL-Zetificat with the encryption, PKCS #1 SHA-1 - AES 128 CBC with SHA 1.

How can I decrypt this code ? ... I tryed everything .. And yes I know, I can use stream socket.. but I will solve this for me with the "normal" php-socket ...

Why am I having trouble decrypting? Is there a solution?

duanmu5039
duanmu5039 你能展示你想要解密的字符串吗?
接近 6 年之前 回复
dongliugu8843
dongliugu8843 “RSA_padding_check_PKCS1_type_2错误...”-您经常会看到(1)文本编码错误-您没有解密二进制数据;而是你试图解密Base64编码的数据。或者(2)您使用的是不匹配的密钥。也就是说,公钥与私钥不匹配。您也应该显示您的密钥(假设私钥是测试密钥)。
接近 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
websocket-建立连接错误:net :: ERR_INSECURE_RESPONSE

<div class="post-text" itemprop="text"> <p>Can't connect to websocket server..</p> <p>I use the exact same <code>private.key</code> and <code>public.crt</code> that I use with <code>nginx</code> </p> <p>The cert is self-signed but works fine with the rest of the website over HTTPS via nginx</p> <p>The websocket server works when using <code>ws://</code> when the line with <code>http.ListenAndServe()</code> is uncommented</p> <pre><code>package main import ( "flag" "fmt" "log" "net/http" ) const PORT uint = 8000 func main(){ host := parse_flags() hub := newHub() go hub.run() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { serve(hub, w, r) }) server_host := fmt.Sprintf("%s:%d", host, PORT) log.Println("Server listening on:", server_host) err := http.ListenAndServeTLS(server_host, fmt.Sprintf("/var/ini/ssl/%s/public.crt", host), fmt.Sprintf("/var/ini/ssl/%s/private.key", host), nil) //err := http.ListenAndServe(server_host, nil) if err != nil { log.Fatal("ListenAndServe:", err) } } </code></pre> </div>

websocket client执行socket_write 就断开连接

php 充当websocket客户端,模拟向服务器端发消息,但是一执行socket_write连接就丢失了。 是因为php是短连接吗?我在服务端有监控发送的消息,没有收到消息。 代码: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $result = socket_connect($socket, '********', ***); echo $result."\n"; echo "Send Command..........\n"; $msg = 'test msg'; socket_write($socket, $msg, strlen($msg)); echo "OK\n"; echo "Reading Backinformatin:\n\n"; while ($out = socket_read($socket, 2048)) { echo $out." out\n"; } echo "Close socket........\n"; //socket_close($socket); echo "OK,He He.\n\n";

loadrunner录制websocket协议

loadrunner录制websocket![图片说明](https://img-ask.csdn.net/upload/201703/28/1490669802_323805.png)

关于lighttpd websocket应用

我想了解一下关于lighttpd的websocket应用,之前看过GitHub上有一个,但是不知道为什么没有办法跑起来,有谁有这方面的资料,求大神提供指导

websocket 服务器推送数据库数据到浏览器

刚接触web方面的知识,想实现一个小项目,就是服务器不断的从数据库里取出最新的数据,然后把数据推送给web浏览器,看资料说websocket可以很好的实现这个功能,但是websocket的API就那几个监听事件,况且Onmessage,在接受到浏览器到服务器,或者服务器到浏览器的数据时,才会执行,但是,我现在不用浏览器发请求,就是浏览器连上服务器后,服务器就一直不断的推送数据到浏览器,用java实现,应该怎么做呢?有谁做过这方面的东西,请说说你们的做法

运行phpwebsocket服务器.php

<div class="post-text" itemprop="text"> <p>I am playing around with phpwebsocket. I got the code from <a href="http://code.google.com/p/phpwebsocket/" rel="nofollow">http://code.google.com/p/phpwebsocket/</a>. the implementation is that I have to run the server.php using command line which starts the socket linstening on a port. but I am wondering if I upload the script to my blog server(one.com), how can I start the server.php without command line? </p> <p>thanks for any tips.</p> </div>

Websocket服务器不允许来自客户端的新连接,卡在socket_read上(没有错误)

<div class="post-text" itemprop="text"> <p>I have websocket server written in native php. I run the server in linux's screen.</p> <p>It works fine. client can connect to the webserver. but after a few days (not sure how many days, happen randomly), the websocket are not accepting new connection anymore.</p> <pre><code>set_time_limit(0); if(!($socket = socket_create(AF_INET, SOCK_STREAM, 0))){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); die(); } if(!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); die(); } if(!socket_bind($socket, 0, $port)){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); die(); } if(!socket_listen($socket)) { $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); die(); } /** * array of client sockets **/ $clientSockets = array($socket); $socketLists = array(); $write = null; $except = null; $header = array(); /** * start endless loop, so that our script doesn't stop **/ while (true) { /** * array of sockets to read * !get from clientSockets array **/ $readSockets = $clientSockets; /** * now call select - blocking call **/ if(socket_select($readSockets , $write , $except , 0, 10) === false) { $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); error_log('Could not listen on socket: ['.$error_code.'] '.$error_msg.' '); } if(in_array($socket, $readSockets)){ /** * Accept new client socket **/ if(($new_client_socket = socket_accept($socket)) !== false){ error_log('Websocket has new connection'); /** * Add new client socket to client socket array **/ $clientSockets[] = $new_client_socket; /** * read data sent by the socket buffer(65536, 65536) **/ error_log('Websocket new connection before read header'); if(!($header = socket_read($new_client_socket, 65536))){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); error_log('Could not read on new_client_socket: ['.$error_code.'] '.$error_msg.' '); } error_log('Websocket new connection after read header =&gt; '.json_encode($header)); $datas = json_decode($header); if ((isset($datas-&gt;type) &amp;&amp; $datas-&gt;type == "server") || (isset($datas-&gt;type) &amp;&amp; $datas-&gt;type == "cec")) { $newDatas = json_decode($datas-&gt;data); $searchIndex = strtolower($newDatas-&gt;ip_address) . '-' . strtolower($newDatas-&gt;mac_address); unset($datas-&gt;type); $response = mask(json_encode($datas)); checkSocketAndSendMessage($clientSockets, $socketLists, $searchIndex, $response); }else{ performHandshaking($header, $new_client_socket, $host, $port); } /** * make room for new socket **/ $found_socket = array_search($socket, readSockets); unset($readSockets[$found_socket]); }else{ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); // die(); } } foreach ($readSockets as $readSocket) { $buf = @socket_read($readSocket, 65536, PHP_NORMAL_READ); if(strlen($buf) &lt; 1){ $socket_index = array_search($readSocket, $clientSockets); $socket_list_index = ''; foreach($socketLists as $key =&gt; $socketList){ if($readSocket == $socketList['index']){ $socket_list_index = $key; } } if(!socket_getpeername($readSocket, $ip)){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); error_log('error disconnect socket_getpeername: ['.$error_code.'] '.$error_msg.' '); } /** * Added to try cater * CLOSE_WAIT problem **/ $linger = array ('l_linger' =&gt; 0, 'l_onoff' =&gt; 1); if(!socket_set_option($clientSockets[$socket_index], SOL_SOCKET, SO_LINGER, $linger)){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); error_log('error disconnect socket_set_option: ['.$error_code.'] '.$error_msg.' '); } if(!socket_close($clientSockets[$socket_index])){ $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); error_log('error disconnect socket_close: ['.$error_code.'] '.$error_msg.' '); } unset($clientSockets[$socket_index]); if(isset($socketLists[$socket_list_index])){ unset($socketLists[$socket_list_index]); } } } } </code></pre> <p>It always stop at <code>error_log('Websocket new connection before read header');</code></p> <p>I expect if there is an error, it will show here <code>error_log('Could not read on new_client_socket: ['.$error_code.'] '.$error_msg.' ');</code></p> <p>But no error came out. It just stuck there.</p> <p>If i try to connect to the websocket, i check <code>netstat -tcp</code> in server, it shows state <code>Established</code>. </p> <p>the status:- <code>tcp 0 0 roomie-devel:cslistener internettl.org:51715 ESTABLISHED 17556/php</code></p> <p>please someone help me, is there any settings in linux that i need to change?</p> <p>i try socket_close, but it return error:- <code>error disconnect socket_close: [104] Connection reset by peer </code></p> <p>there's also error in socket_getpeername() and another socket_close() error:- <code>PHP Warning: socket_getpeername(): unable to retrieve peer name [107]: Transport endpoint is not connected in /var/www/html/webSocket/webSocket.php on line 296</code></p> <p><code>error disconnect socket_getpeername: [107] Transport endpoint is not connected </code></p> <p><code>error disconnect socket_close: [107] Transport endpoint is not connected </code></p> <p>based on my research, to close tcp connection, both end need to send close connection request. but you cannot called the socket_close if client is unexpectedly close their connection (for eg: they force shutdown their computer). how do i properly close connection for this situation? do i need to set anything in linux to close any socket not properly close?</p> </div>

WebSocket连接失败:连接建立错误:net :: ERR_CONNECTION_REFUSED

<div class="post-text" itemprop="text"> <p>我正在使用Ratchet创建一个聊天的网页接口,弹跳出错误提示:</p> <p><code>main.js</code>:2 WebSocket 连接 <code>ws://localhost:8080/</code></p> <p><code>failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED</code></p> <p>我得到错误的代码如下:</p> <pre><code>$(document).ready(function () { var conn = new WebSocket('ws://localhost:8080'); var chatForm = $(".chatForm"), messageInputField = chatForm.find("#message"), messagesList = $(".messages-list"), usernameForm = $(".username-setter"), usernameInput = usernameForm.find(".username-input"); </code></pre> <p>我也改变了IP地址 <code>/etc/host</code> 为 <code>0.0.0.0</code> 只是为了确认。 你有什么建议来改变和修正这个错误吗?</p> </div>

如何在停止服务器或长时间重启服务器后自动启动websocket服务器

<div class="post-text" itemprop="text"> <p>I am using the ratchet websocket server on CentOs. The problem is it is stopped after some time. I have used the screen command to solve the problem but when server is rebooted it does not start automatically. Is there any way to start the websocket server automatically when it was stopped or killed or server was restarted?</p> </div>

WebSocket连接失败:连接建立错误:net :: ERR_SSL_PROTOCOL_ERROR

<div class="post-text" itemprop="text"> <p>当我试图通过wss://连接到WebSocket时,我为什么会得到这个错误,但是在ws://上却没问题呢?</p> <h1>错误:</h1> <pre><code>WebSocket connection failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR </code></pre> <h1>代码:</h1> <pre><code>package main import ( "fmt" "log" "net/http" //"encoding/json" "github.com/gorilla/websocket" ) var clients map[*websocket.Conn]*Client var upgrader = websocket.Upgrader{ CheckOrigin : func(r *http.Request) bool{ return true }, } type Client struct{ session_id string block_id uint module string } func main(){ var port uint = 8000 http.HandleFunc("/", handleConnections) log.Printf("Websocket server started on: %d", port) err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil) if err != nil { log.Fatal("ListenAndServe: ", err) } } func handleConnections(w http.ResponseWriter, r *http.Request){ // Upgrade initial GET request to a websocket ws, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Print(err) return } defer ws.Close() log.Print("Connection established to IP: ", r.RemoteAddr) ... } </code></pre> </div>

使用nodejs客户端访问golang websocket服务器

<div class="post-text" itemprop="text"> <p>I am a newbie to NodeJS. Assume that I have a echo server implemented with Golang's websocket package:</p> <pre> package main import ( "code.google.com/p/go.net/websocket" "log" "net/http" ) func EchoServer(ws *websocket.Conn) { var msg string websocket.Message.Receive(ws, &amp;msg) log.Printf("Message Got: %s ", msg) websocket.Message.Send(ws, msg) } func main() { http.Handle("/echo", websocket.Handler(EchoServer)) err := http.ListenAndServe(":8082", nil) if err != nil { panic(err.Error()) } } </pre> <p>What should the nodejs client code look like ? </p> </div>

WebSocket客户端与Java的Socket服务器通信

客户端使用websocket,服务器使用Java Socket。客户端经过new webSocket(utl)之后,服务器端可以收到请求头,但是客户端的webSocket.readyState一直是0,没有连接成功,这个是因为什么呢?是不是因为服务器端不可以用Java Socket

Websocket:无法与基本websocket服务器建立连接

<div class="post-text" itemprop="text"> <p>I've tried very basic websocket tutorial using ratchet php, exactly as shown in <a href="http://socketo.me/docs/hello-world" rel="nofollow">http://socketo.me/docs/hello-world</a></p> <p>Code for websocket server:</p> <pre><code>&lt;?php error_reporting(E_ALL); ini_set('display_errors', '1'); require 'vendor/autoload.php'; require 'chat.php'; use Ratchet\Server\IoServer; use HHWS\Chat; $server = IoServer::factory( new Chat(), 8080 ); $server-&gt;run(); </code></pre> <p>To run the server I did:</p> <pre><code>$ php ws-server.php </code></pre> <p>And to test the connection with the server I did:</p> <pre><code>telnet 127.0.0.1 8080 </code></pre> <p>This worked perfectly fine when tested LOCALLY. Users can chat using multiple telnet terminals. </p> <p>I then uploaded the code to live server. And the tried running the server. Then tried to connect to this server using telnet just like before, it couldn't connect. All it shows is "Trying.." message and then " Unable to connect to remote host: Connection timed out".</p> <p>I don't know why this is happening, and what the problem is. The code is exactly the same. And this is very basic hello world example I'm doing. Can anyone help me on this. Do using "Websockets" have any other requirements on the live server to work. </p> <p><strong>Update:</strong> Actually, the live server is <strong>Amazon EC2</strong>; does this require setting up additional things for websocket to work?</p> </div>

使用PHP发送到WebSocket服务器?

<div class="post-text" itemprop="text"> <p>I'm running a Node.js WebSocket server on port 3000 on the same machine that I'm running Apache/PHP by running a reverse-proxy through Apache. This is my HTTPD file:</p> <pre><code> &lt;VirtualHost *:80&gt; ProxyRequests off SSLProxyEngine on ProxyPass /node/ ws://localhost:3000/node/ ProxyPassReverse /node/ ws://localhost:3000/node/ &lt;/VirtualHost&gt; &lt;VirtualHost *:443&gt; ProxyRequests off SSLProxyEngine on ProxyPass /node/ ws://localhost:3000/node/ ProxyPassReverse /node/ ws://localhost:3000/node/ &lt;/VirtualHost&gt; </code></pre> <p>Let's say my domain name is "example.com". Then, to connect to the WebSocket server through a browser, I would use this JS:</p> <pre><code>var connection = new WebSocket("wss://example.com/node/"); </code></pre> <p>This works fine, and I'm successfully sending and receiving messages from browsers.</p> <p>However, I also need to be able to send (not receive) messages to the WebSocket server using PHP, from the same machine. I've tried several configurations of fsockopen, and none of them have worked. Here are the ones I've tried, with the resulting error messages:</p> <pre><code>$fp = fsockopen("example.com/node/", 3000); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("ssl://example.com/node/", 3000); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("tls://example.com/node/", 3000); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("http://example.com/node/", 3000); //Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? $fp = fsockopen("https://example.com/node/", 3000); //Unable to find the socket transport "https" - did you forget to enable it when you configured PHP? $fp = fsockopen("wss://example.com/node/", 3000); //Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP? $fp = fsockopen("ws://example.com/node/", 3000); //Unable to find the socket transport "ws" - did you forget to enable it when you configured PHP? $fp = fsockopen("example.com/node/", 443); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("ssl://example.com/node/", 443); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("tls://example.com/node/", 443); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("http://example.com/node/", 443); //Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? $fp = fsockopen("https://example.com/node/", 443); //Unable to find the socket transport "https" - did you forget to enable it when you configured PHP? $fp = fsockopen("wss://example.com/node/", 443); //Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP? $fp = fsockopen("ws://example.com/node/", 443); //Unable to find the socket transport "ws" - did you forget to enable it when you configured PHP? $fp = fsockopen("example.com/node/", 80); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("ssl://example.com/node/", 80); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("tls://example.com/node/", 80); //php_network_getaddresses: getaddrinfo failed: Name or service not known $fp = fsockopen("http://example.com/node/", 80); //Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? $fp = fsockopen("https://example.com/node/", 80); //Unable to find the socket transport "https" - did you forget to enable it when you configured PHP? $fp = fsockopen("wss://example.com/node/", 80); //Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP? $fp = fsockopen("ws://example.com/node/", 80); //Unable to find the socket transport "ws" - did you forget to enable it when you configured PHP? </code></pre> <p>I've also tried all of those configurations using "localhost" and "127.0.0.1". And I've also experimented using the built-in PHP library functions socket_create and socket_connect, with all of those same hostnames, IP's, and ports - all resulting in the same types of "unknown host" errors. What am I doing wrong? What is the right way to do this?</p> </div>

WebSocket JWT令牌连接授权

<div class="post-text" itemprop="text"> <p>I am trying to make a websocket connection to a URL(python client) which needs to have a jwt token passed in and the server(implemented in GO) listens to this request on and is supposed to authenticate by parsing the token.</p> <p>I try to use this part of the code to make the request - </p> <pre><code>def test_auth_token(token) conn = create_connection("ws://&lt;IP&gt;:port"+ '/'+ container.uuid + '?token='+token) result = conn.recv() assert result is not None </code></pre> <p>This request hits the server which runs this code to validate this request</p> <p>func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err error) {</p> <pre><code>// Look for an Authorization header if ah := req.Header.Get("Authorization"); ah != "" { // Should be a bearer token if len(ah) &gt; 6 &amp;&amp; strings.ToUpper(ah[0:6]) == "BEARER" { return Parse(ah[7:], keyFunc) } } // Look for "access_token" parameter req.ParseMultipartForm(10e6) if tokStr := req.Form.Get("access_token"); tokStr != "" { return Parse(tokStr, keyFunc) } return nil, ErrNoTokenInRequest </code></pre> <p>}</p> <p>Every time, I am getting the "ErrNoTokenInRequest" output despite I am passing the token as a query parameter. The server side token validation is being done by this external library which contains the above GO Routine - <a href="https://github.com/dgrijalva/jwt-go/blob/master/jwt.go" rel="nofollow">https://github.com/dgrijalva/jwt-go/blob/master/jwt.go</a></p> <p>I am not sure, what could be the possible reasons that server doesn't find the token sent in my client? Is it supposed to be sent as payload or headers or something else? Could someone point to get this module working?</p> <p>With "access_token" as query parameter i get this exception - </p> <pre><code>self = &lt;websocket._core.WebSocket object at 0x10a15a6d0&gt; host = 'x.x.x.x.', port = 9345 resource = '/v1/stats/fff51e85-f2bb-4ace-8dcc-fde590932cca?access_token=eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MjIxMzEyMzUsInN1YiI6ImNh...vxvBmtZRrUTY5AcvrjbojXqLxFHL_CMsmTZfTXhOiy-7W2V95bqts2Wy4R8oQvsfDylYJWCBTzZNKHvPVFpcl0jQKLm1ms-LOJg1w-k23VfojZucPGtY5A' options = {} headers = ['GET /v1/stats/fff51e85-f2bb-4ace-8dcc-fde590932cca?access_token=eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MjIxMzEyMzUsInN1YiI... 'Host: x.x.x.x.:9345', 'Origin: http://x.x.x.x.:9345', 'Sec-WebSocket-Key: BN1n2BcCT/CUGh9MHeyL5g==', ...] key = 'BN1n2BcCT/CUGh9MHeyL5g==' header_str = 'GET /v1/stats/fff51e85-f2bb-4ace-8dcc-fde590932cca?access_token=eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE0MjIxMzEyMzUsInN1YiI6...3:9345 Origin: http://192.168.59.103:9345 Sec-WebSocket-Key: BN1n2BcCT/CUGh9MHeyL5g== Sec-WebSocket-Version: 13 </code></pre> </div>

websocket 服务器端onmessage中遍历发送消息后触发error,

对应进程的客户端也没收到消息,由于线程退出或应用程序请求,已中止 I/O 操作。 遍历部分和异常部分代码: WsHandler client = list.Find(obj => obj.Uid.ToLower() == rooms[i].UserUid.ToLower()); if (client != null && client.WebSocketContext.WebSocket.State == WebSocketState.Open) { // client.WebSocketContext.WebSocket.State client.Send(message); } /// <summary> /// 异常 /// </summary> public override void OnError() { if (this.Error != null) { Core.Logger.Log.Write(this.Error.ToString(), Core.Logger.MessageType.Error); } try { WsWorker.list.Remove(this); } catch (Exception ex) { Core.Logger.Log.Write(ex.ToString(), Core.Logger.MessageType.Error); } } ------------------------------------------------------ onerror之后出发了onclose,但是客户端没有收到close的消息,个人判断可能是因为路由等中间原因导致客户端判断连接正常,没有发起重新连接请求,不知道加个心跳机制能不能解决问题,或者有更好的方法。

PHP-Websocket:socket_recv()和socket_getpeername()的问题

<div class="post-text" itemprop="text"> <p>I'm using PHP Websocket and sometimes, I get the following both warnings.<br> Warning-1:</p> <blockquote> <p>socket_recv(): An existing connection was forcibly closed by the remote host</p> </blockquote> <p>Warning-2:</p> <blockquote> <p>socket_getpeername(): unable to retrieve peer name [107]: Transport endpoint is not connected</p> </blockquote> <p>I send messages to the Websocket by another PHP-Script. This PHP-Script sends a message and if it's finised, the Socket-Call ends. <br> So this Warning is probably correct, because the "endpoint" (= the PHP-Script) is no loger connected.<br> But this Warning is not beautiful..<br><br> So this is the following Code for Websocket, which is received the messages: </p> <pre><code>define('HOST_NAME',$host_ip); define('PORT',$socket_port); $null = NULL; $socketHandler = new SocketHandler(); $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($socketResource, SOL_SOCKET, SO_REUSEADDR, 1); socket_bind($socketResource, 0, PORT); socket_listen($socketResource); $clientSocketArray = array($socketResource); while (true) { $newSocketArray = $clientSocketArray; socket_select($newSocketArray, $null, $null, 0, 10); if (in_array($socketResource, $newSocketArray)) { $newSocket = socket_accept($socketResource); $clientSocketArray[] = $newSocket; $header = socket_read($newSocket, 1024); $socketHandler-&gt;doHandshake($header, $newSocket, HOST_NAME, PORT); socket_getpeername($newSocket, $client_ip_address); $newSocketIndex = array_search($socketResource, $newSocketArray); unset($newSocketArray[$newSocketIndex]); } foreach ($newSocketArray as $newSocketArrayResource) { while(socket_recv($newSocketArrayResource, $socketData, 1024, 0) &gt;= 1){ $socketMessage = $socketHandler-&gt;unseal($socketData); $messageObj = json_decode($socketMessage); break 2; } $socketData = @socket_read($newSocketArrayResource, 1024, PHP_NORMAL_READ); if ($socketData === false) { socket_getpeername($newSocketArrayResource, $client_ip_address); $newSocketIndex = array_search($newSocketArrayResource, $clientSocketArray); unset($clientSocketArray[$newSocketIndex]); } } } socket_close($socketResource); </code></pre> <p>The command, which produces the Warning-1 </p> <blockquote> <p>socket_recv(): An existing connection was forcibly closed by the remote host</p> </blockquote> <p>is:</p> <blockquote> <p>while(socket_recv($newSocketArrayResource, $socketData, 1024, 0) &gt;= 1)</p> </blockquote> <p>In the <a href="http://php.net/manual/en/function.socket-recv.php" rel="nofollow noreferrer">PHP-Manual</a> there is mentioned to get the return-value of socket_recv(). But in the examples there is only shown to execute socket_recv() once, by using if(). <br> But I use socket_recv() within the loop-header. <br> So my question: <br> <b>How do I check return-value in my case - by using socket_recv() within a loop-header?</b></p> <p>Warning-2 </p> <blockquote> <p>socket_getpeername(): unable to retrieve peer name [107]: Transport endpoint is not connected</p> </blockquote> <p>was produced with the following code:</p> <blockquote> <p>socket_getpeername($newSocketArrayResource, $client_ip_address);</p> </blockquote> <p>My question is:<br> <b>What have I to do in order not to execute socket_getpeername(), if the client is no longer connected?</b></p> <p>Maybe someone can help me to fix these Warnings. It's very difficult do watch, because these Warings do not always appear..</p> <p>Bye, Chris</p> </div>

使用autocert保护安全的Websocket服务器

<div class="post-text" itemprop="text"> <p>I am trying to setup a secure websocket server (<code>wss://</code>) in go using <code>acme/autocert</code>. The program starts, but when I try to connect to it I get the following error: </p> <pre><code>http: TLS handshake error from &lt;IP&gt;: acme/autocert: unable to authorize "&lt;my domain&gt;"; challenge "tls-alpn-01" failed with error: acme: authorization error for &lt;my domain&gt;: 403 urn:acme:error:unauthorized: Cannot negotiate ALPN protocol "acme-tls/1" for tls-alpn-01 challenge </code></pre> <p>This is the code I am using to start the websocket server:</p> <pre><code>func Run() { hub = newHub() go hub.run() mux := http.NewServeMux() mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { serveWs(hub, w, r) }) certManager := autocert.Manager{ Prompt: autocert.AcceptTOS, Cache: autocert.DirCache("certs"), } server := &amp;http.Server{ Addr: ":8080", Handler: mux, TLSConfig: &amp;tls.Config{ GetCertificate: certManager.GetCertificate, }, } go server.ListenAndServeTLS("", "") } </code></pre> <p>It should automatically get a new certificate when there is none in the cache (<code>certs</code> folder). The error message tells me that there is a problem while negotiating the protocol when creating a new certificate. Do I need to add supported protocols somewhere?</p> </div>

WebSocket可以让2个外网服务器间进行双向通讯吗?

网上WebSocket都是浏览器(客户端)和服务器(服务端)的代码。 我想让2个不同外网的后台服务器双向连接怎么写?能实现吗? 如果能,麻烦贴上后台java怎么连服务端的代码。不需要服务端的代码。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Vue + Spring Boot 项目实战(十九):Web 项目优化解决方案

快来一起探索如何打脸我们的破项目,兄弟姐妹们把害怕打在公屏上!

你连存活到JDK8中著名的Bug都不知道,我怎么敢给你加薪

CopyOnWriteArrayList.java和ArrayList.java,这2个类的构造函数,注释中有一句话 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList(Collection&lt;? ...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

CSDN:因博主近期注重写专栏文章(已超过150篇),订阅博主专栏人数在突增,近期很有可能提高专栏价格(已订阅的不受影响),提前声明,敬请理解!

CSDN:因博主近期注重写专栏文章(已超过150篇),订阅博主专栏人数在突增,近期很有可能提高专栏价格(已订阅的不受影响),提前声明,敬请理解! 目录 博客声明 大数据了解博主粉丝 博主的粉丝群体画像 粉丝群体性别比例、年龄分布 粉丝群体学历分布、职业分布、行业分布 国内、国外粉丝群体地域分布 博主的近期访问每日增量、粉丝每日增量 博客声明 因近期博主写专栏的文章越来越多,也越来越精细,逐步优化文章。因此,最近一段时间,订阅博主专栏的人数增长也非常快,并且专栏价

一个HashMap跟面试官扯了半个小时

一个HashMap能跟面试官扯上半个小时 关注 安琪拉的博客 1.回复面试领取面试资料 2.回复书籍领取技术电子书 3.回复交流领取技术电子书 前言 HashMap应该算是Java后端工程师面试的必问题,因为其中的知识点太多,很适合用来考察面试者的Java基础。 开场 面试官: 你先自我介绍一下吧! 安琪拉: 我是安琪拉,草丛三婊之一,最强中单(钟馗不服)!哦,不对,串场了,我是**,目...

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

培训班出来的人后来都怎么样了?(二)

接着上回说,培训班学习生涯结束了。后面每天就是无休止的背面试题,不是没有头脑的背,培训公司还是有方法的,现在回想当时背的面试题好像都用上了,也被问到了。回头找找面试题,当时都是打印下来天天看,天天背。 不理解呢也要背,面试造飞机,上班拧螺丝。班里的同学开始四处投简历面试了,很快就有面试成功的,刚开始一个,然后越来越多。不知道是什么原因,尝到胜利果实的童鞋,不满足于自己通过的公司,嫌薪水要少了,选择...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

工作八年,月薪60K,裸辞两个月,投简历投到怀疑人生!

近日,有网友在某职场社交平台吐槽,自己裸辞两个月了,但是找工作却让自己的心态都要崩溃了,全部无果,不是已查看无回音,就是已查看不符合。 “工作八年,两年一跳,裸辞两个月了,之前月薪60K,最近找工作找的心态崩了!所有招聘工具都用了,全部无果,不是已查看无回音,就是已查看不符合。进头条,滴滴之类的大厂很难吗???!!!投简历投的开始怀疑人生了!希望 可以收到大厂offer” 先来看看网...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

程序员是做全栈工程师好?还是专注一个领域好?

昨天,有位大一的同学私信我,说他要做全栈工程师。 我一听,这不害了孩子么,必须制止啊。 谁知,讲到最后,更确定了他做全栈程序员的梦想。 但凡做全栈工程师的,要么很惨,要么很牛! 但凡很牛的,绝不是一开始就是做全栈的! 全栈工程师听起来好听,但绝没有你想象的那么简单。 今天听我来给你唠,记得帮我点赞哦。 一、全栈工程师的职责 如果你学习编程的目的只是玩玩,那随意,想怎么学怎么学。...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

什么是a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站?00后的世界我不懂!

A站 AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站。A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量互动弹幕,是中国弹幕文化的发源地;拥有大量超粘性的用户群体,产生输出了金坷垃、鬼畜全明星、我的滑板鞋、小苹果等大量网络流行文化,也是中国二次元文化的发源地。 B站 全称“哔哩哔哩(bilibili...

十个摸鱼,哦,不对,是炫酷(可以玩一整天)的网站!!!

文章目录前言正文**1、Kaspersky Cyberthreat real-time map****2、Finding Home****3、Silk – Interactive Generative Art****4、Liquid Particles 3D****5、WINDOWS93****6、Staggering Beauty****7、Ostagram图片生成器网址****8、全历史网址*...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

用了这个 IDE 插件,5分钟解决前后端联调!

点击上方蓝色“程序猿DD”,选择“设为星标”回复“资源”获取独家整理的学习资料!作者 |李海庆我是一个 Web 开发前端工程师,受到疫情影响,今天是我在家办公的第78天。开发了两周,...

大厂的 404 页面都长啥样?最后一个笑了...

每天浏览各大网站,难免会碰到404页面啊。你注意过404页面么?猿妹搜罗来了下面这些知名网站的404页面,以供大家欣赏,看看哪个网站更有创意: 正在上传…重新上传取消 腾讯 正在上传…重新上传取消 网易 淘宝 百度 新浪微博 正在上传…重新上传取消 新浪 京东 优酷 腾讯视频 搜...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

Java14 新特性解读

Java14 已于 2020 年 3 月 17 号发布,官方特性解读在这里:https://openjdk.java.net/projects/jdk/14/以下是个人对于特性的中文式...

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

前端还能这么玩?(女朋友生日,用前端写了一个好玩的送给了她,高兴坏了)

爬虫(101)爬点重口味的

小弟最近在学校无聊的很哪,浏览网页突然看到一张图片,都快流鼻血。。。然后小弟冥思苦想,得干一点有趣的事情python 爬虫库安装https://s.taobao.com/api?_ks...

工作两年简历写成这样,谁要你呀!

作者:小傅哥 博客:https://bugstack.cn 沉淀、分享、成长,让自己和他人都能有所收获! 一、前言 最近有伙伴问小傅哥,我的简历怎么投递了都没有反应,心里慌的很呀。 工作两年了目前的公司没有什么大项目,整天的维护别人的代码,有坑也不让重构,都烦死了。荒废我一身技能无处施展,投递的简历也没人看。我是不动物园里的猩猩,狒狒了! 我要加班,我要996,我要疯狂编码,求给我个机会… ...

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问