@@ -80,7 +80,11 @@ public function onText(
8080 echo "Client pub for $ body \n" ;
8181 if (isset ($ this ->subscriptions [$ body ])) {
8282 foreach ( $ this ->subscriptions [$ body ] as $ client ) {
83- $ client ->send (new \WebSocket \Message \Text ("pub $ body " ));
83+ try {
84+ $ client ->send (new \WebSocket \Message \Text ("pub $ body " ));
85+ } catch (\Throwable $ e ) {
86+ echo "> ERROR SENDING: {$ e ->getMessage ()}\n" ;
87+ }
8488 }
8589 }
8690 break ;
@@ -90,7 +94,11 @@ public function onText(
9094 if ( $ connection ->getRemoteName () == $ client ->getRemoteName () ) {
9195 continue ;
9296 }
93- $ client ->send (new \WebSocket \Message \Text ("Client " . $ connection ->getRemoteName () . " said $ message \n" ));
97+ try {
98+ $ client ->send (new \WebSocket \Message \Text ("Client " . $ connection ->getRemoteName () . " said $ message \n" ));
99+ } catch (\Throwable $ e ) {
100+ echo "> ERROR SENDING: {$ e ->getMessage ()}\n" ;
101+ }
94102 }
95103 break ;
96104 }
@@ -134,6 +142,15 @@ public function onError(
134142 ) {
135143 $ name = $ connection ? "[ {$ connection ->getRemoteName ()}] " : "[-] " ;
136144 echo "> {$ name } Error: {$ exception ->getMessage ()}\n" ;
145+ echo "Client " . $ connection ->getRemoteName () . " errored - disconnecting \n" ;
146+ foreach ($ this ->subscriptions as $ url => $ subscribers ) {
147+ foreach ($ subscribers as $ key => $ client ) {
148+ if ($ client ->getRemoteName () == $ connection ->getRemoteName ()) {
149+ echo "Removing subscription for $ url \n" ;
150+ unset($ subscribers [$ url ][$ key ]);
151+ }
152+ }
153+ }
137154 }
138155
139156 public function createServer () {
0 commit comments