Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awesome code BTW Unexpected response code: 403 #241

Open
jeromystewart opened this issue Aug 27, 2020 · 6 comments
Open

Awesome code BTW Unexpected response code: 403 #241

jeromystewart opened this issue Aug 27, 2020 · 6 comments

Comments

@jeromystewart
Copy link

jeromystewart commented Aug 27, 2020

In your SocketIO chat example I changed one thing/one line
$io = new SocketIO(3000);

When I attempt to connect using my javascript library, I get:
WebSocket connection to 'ws://10.204.1.76:3000/' failed: Error during WebSocket handshake: Unexpected response code: 403

Of course the server address where the php daemon is being executed is: ip a = 10.204.1.76

I've opened port 3000 on the client machine and I have also tested other socket servers that work using the same JavaScript library. They work. If I just simply switch my php script to another library, it connects and broadcasts/emits/sends messages just fine. Because of this, I know that my client firewall ports are appropriately setup and that my ports on the server are allowing port 3000.

I noticed the following line in the SocketIO Class file:
$worker = new Worker('SocketIO://0.0.0.0:'.$port, $opts);

I am guessing this just means "use the servers IP" ?? Is this correct?

Please Help.

Thanks again for this awesome library, I can tell you and your contributors are at the top of the game .. cheers

@jeromystewart jeromystewart changed the title Awesome code BTW net::ERR_CONNECTION_REFUSED Awesome code BTW Unexpected response code: 403 Aug 27, 2020
@jeromystewart
Copy link
Author

image

@walkor
Copy link
Owner

walkor commented Aug 28, 2020

I noticed the following line in the SocketIO Class file:
$worker = new Worker('SocketIO://0.0.0.0:'.$port, $opts);
I am guessing this just means "use the servers IP" ?? Is this correct?

Yes.

new Worker('SocketIO://0.0.0.0:'.$port, $opts);

0.0.0.0 means listening to all IP(include 127.0.0.1 and Intranet IP and Internet IP) of the local network card.

But I can not tell you what problem. Can you give me a public url to test?

@jeromystewart
Copy link
Author

Thanks much for your prompt response, I think eventually I can troubleshoot the problem by looking at your library and attempting to intercept the actual issue .. following your class logic. I found the precise spot where the 403 header is being sent. I just have to start debugging and log the backtrace.

Unfortunately, all of my servers are behind a corporate firewall, I am testing the feasibility of several libraries including yours.

If I can get a public server running so you can inspect this further, I will let you know.

-Jeromy Stewart

@jeromystewart
Copy link
Author

I've traced the error so far to self::ERROR_UNKNOWN_TRANSPORT

As for the reason, the following statement evaluates to true

if(!isset($req->_query['transport'])
|| !isset(self::$allowTransports[$req->_query['transport']]))

In method Engine::verify()

Does this help?

@jeromystewart
Copy link
Author

jeromystewart commented Aug 28, 2020

I found an obscure issue in my investigation.

If I cause an error right before this line:
(Engine::sendErrorMessage())
$res->writeHead(403, '', $headers);

I can successfully connect and send messages. Otherwise the 403 message prevents connection.

I originally caused the error and discovered the issue by attempting to output your serialized $req object as shown below:

$file = '/var/log.txt';
$reslt = file_put_contents ($file,serialize($req),FILE_APPEND);
if($reslt === false){
echo 'cannot write';
exit;
}

This resulted in:

Serialization of 'Closure' is not allowed in /var/wmss/workerman/phpsocket.io/src/Engine/Engine.php:110

But because of the error, my web socket connection and subsequent message sending started to work suddenly.

Can you help please?

@jeromystewart
Copy link
Author

jeromystewart commented Aug 28, 2020

Okay so I discovered that the error was causing success because it was simply halting the output of the 403 and the method execution was being halted right before the line:

this line: $res->writeHead(403, '', $headers);

Because of the halt in executing the remaining code, my socket connected successfully. Does this help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants