-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
WebSocket: After calling $webSockerServer->push() from within onMessage event, the WebSocket connection closes by calling onClose event. #5372
Comments
You need to check if the third parameter |
@NathanFreeman
and got: client 1 closed In order to keep a connection opened, do i need to push() (stream) some data continously from server-side (or from the client-side) by puting push() (or send() ) inside a loop ? If the answer is "Yes" then what i will take from this is that push() only sends the data (from the server to the client) and then websocket connection is closed after every push. |
$reactorId greater than 0 indicates that the client has actively closed the connection. You need to check the client's code. |
@NathanFreeman For the (WebSocket's) client-side, I am using this gist (with swoole version 5.1.2) https://gist.github.com/NHZEX/946275e9b32a832d579a36c5d3d0b7fc If you just look at this code, the $this->socket->send() function is passing four parameters to Server::pack() (as shown in function below at the end, so initially it was not working). I removed the fourth parameter in order to make the code work (by conforming to the definition of Server::pack(), as per documentation), however i found two things that; A) That, the third parameter (which is int $flags) work only for value "true", or non-zero value, but not for "false" or 0 ) which means i can not set $flag a value other than "WEBSOCKET_FLAG_FIN" (same is also on server-side) and ... So it looks like that the problem lies in how you deal internally with the value of the argument
In code above, i changed ... // see, four parameters (may be because it is code targeting older version of swoole) to ... // Three parameters instead of four It works with only "true" and "non-zero" values not with "false" and 0. (and parhaps passing the "true" and "non-zero" value also disconnects the connection, just as you say that disconnection is coming from client-side of code; May be this is because when we pass "true" or "non-zero" value then it is same as the default value of int $flags (which is "WEBSOCKET_FLAG_FIN"), whereas if i try to pass a Zero value or a boolean false, i get error as it takes the flow of code into .... So, again the question is: How to use server::pack(), and push() (with new type of paramater "int $flags") such that the WebSocker connection do not auto disconnect ? |
Any update on this issue ? Please, also see my last reply. |
I have found that there comes an issue in your client-side recv() function of socket object ...
When server-side pushes all the messages, the function recv() returns not only "false" (false is just fine, as per documentation) but it also issues a warning as below:
And, it also gives a warning that there is no property $errMsg on socket object. Reference to Client-side Code: |
Same problem after update from v4.8.12 to 5.1.3, push($fd, $data) works every other time. |
Way around:
here
FYI. |
Please answer these questions before submitting your issue.
Below is WebSocket Controller Class as included with include_once DIR . '/Controllers/WebSocketController.php' in onOpen event:
Note: i am using WebsocketClient.php (and websocketclient_examples.php ) as provided in repo.
2. What did you expect to see?
I expect not to see the message "client 1 closed" as echoed by the onClose event handler. I am new to WebSocket Programming so i think that WebSocket connection remains opened even after something is pushed from the server to the browser / client.
The message "client 1 closed" (1 is $fd here) as echoed by the onClose event handler
The fd '1' here is also incremented, everytime i re-send a frame using WebSocket client.
php --ri swoole
)?swoole
Swoole => enabled
Author => Swoole Team [email protected]
Version => 5.1.2
Built => May 26 2024 22:51:27
coroutine => enabled with thread context
debug => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
c-ares => 1.18.1
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled
coroutine_pgsql => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => On => On
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
uname -a
&php -v
&gcc -v
) ?Linux HP-Laptop 5.17.5-76051705-generic #202204271406
165150484020.04~63e51bd-Ubuntu SMP PREEMPT Wed Ma x86_64 x86_64 x86_64 GNU/LinuxPHP 8.3.8 (cli) (built: Jun 6 2024 16:58:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1
22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=222.04)Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1
The text was updated successfully, but these errors were encountered: