Home > PHP Framework > Workerman > What should I do if the workerman client cannot connect?

What should I do if the workerman client cannot connect?

藏色散人
Release: 2019-12-12 14:19:15
Original
4229 people have browsed it

What should I do if the workerman client cannot connect?

workermanWhat should I do if the client cannot connect?

Cause of client connection failure

The client will generally report two errors when the connection fails, connection refuse and connection timeout

connection refuse

Generally the reasons are as follows:

1. The port the client connects to is wrong

2. The domain name the client connects to or The ip is wrong

3. If the client uses a domain name to connect, the domain name may point to the wrong server ip

4. The server is not started or the port is not monitored

5. Network proxy software is used

6. The server monitoring IP and the access address are not in the same address segment. For example, if the server monitors 127.0.0.1, the client can only connect through 127.0.0.1 and cannot connect through LAN IP or external network IP. It is recommended that the listening address be set to 0.0.0.0, so that the local machine, internal network, and external network can connect.

connection timeout

It is usually due to the following reasons:

1. The server firewall blocks the connection. You can temporarily close the firewall and try

2. If it is a cloud server, the security group may also prevent the connection from being established. You need to open the corresponding port in the management background.

3. The server does not exist or is not started.

4. If the client uses a domain name to connect, the domain name may point to the wrong server IP

5. The IP accessed by the client is the server’s intranet IP, and the client and the server are not in the same LAN

Other errors

If the error that occurs is not connection refuse and connection timeout, it is generally due to the following reasons:

1. The communication protocol used by the client is inconsistent with the server.

For example, the server uses the http communication protocol, and the client cannot connect using the websocket communication protocol. If the client connects using the websocket protocol, the server must also use the websocket protocol. If the server is a service of http protocol, then the client must use http protocol to access.

The principle here is similar to that if you want to communicate with British people, then use English. If you want to communicate with Japanese people, use Japanese. The language here is similar to a communication protocol. Both parties (client and server) must use the same language to communicate, otherwise communication will not be possible.

Common errors caused by inconsistent communication protocols are:

WebSocket connection to 'ws://xxx.com:xx/' failed: Error during WebSocket handshake: Unexpected response code: xxx
WebSocket connection to 'ws://xxx.com:xx/' failed: Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE
Copy after login

Solution:

It can be seen from the above two errors that the client uses the ws connection and the websocket protocol . The server also needs to use the websocket protocol. Some of the server-side listening codes need to specify the websocket protocol to communicate, for example, as follows

If it is a gatewayWorker, the listening part of the code is similar

// websocket协议,这样客户端才能用ws://...来连。xxxx为端口不用改动
$gateway = new Gateway('websocket://0.0.0.0:xxxx');
Copy after login

If it is a Workerman Is

// websocket协议,这样客户端才能用ws://...来连。xxxx为端口不用改动
$worker = new Worker('websocket://0.0.0.0:xxxx');
Copy after login

Recommended: workerman tutorial

The above is the detailed content of What should I do if the workerman client cannot connect?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template