Cakephp 5 Socket Cake\Network

Hi developer! I hope all are well,
I need to take help about sockets in cakephp, i just read cakephp 5 Apis Cake\Network this class provide Socket instance and i setup everything as they defined in documents but get Connection timed out Error, let me show you my applications screenshots please glace at on them

RemoteController.php:- there is two methods index as server and client

RemoteController:- client method send message in socket
Screenshot from 2024-07-30 10-57-57

RemoteController.php:- index method return error in lastError key Connection timed out error

please help me, how to read data from client? or I am doing something Wrong here

So you `re trying to do is a websocket that can send then received?

hmmm! yes kind of!

actually client action send message but index action does not get anything its show me loading and after 30 seconds it show lastError message timeout… obviously it has throw timeout because default time limit 30 seconds.

can you @Rods help me sir, how does it work or how can i read message from client in real time

you can use websocket for it
Pusher | Leader In Realtime Technologies

so technically your making a chat application?

yes like chat and for qrcode login or anything which I want. but my question is about how to it work Cake\Network\Socket; in cakephp 5. I am asking how to work $socket->read() method? and how does it work. if cakephp provide it pre-installed in cakephp so why it does not working? its does not concern what i am building Chat application or Other but the point is how to does work… cakephp 5 docs not elaborate about cake\network\socket in detail it just give basic idea. please if possible help how can i do this not by third party like pusher… i already know how embed pusher in cakephp

To listen on a socket, it needs to be in a long-running process, not a controller action. This isn’t really a Cake thing, it’s just how sockets work, hence why the Cake docs don’t go into a lot of detail about it.

1 Like

sorry I cant help you any further, but In making chat applications you should use websockets.

I think you are confusing the network socket with the websocket. The \Cake\Network\Socket class is used to handle/maintain connection with the network sockets (i.e. external services, ftp, etc.).

1 Like

Hi ishan thanks for reply… can you please explain more it… in detail and in depth. What exactly mean network socket and websocket mean. I am really confured about it sir

Network socket is what the Cake class you’ve mentioned uses. It’s a completely generic socket for network communications, you need to build whatever protocol you want to run on top of it.

Websocket is a particular socket protocol specially for doing things like chat applications.

If you want to be building a chat application, you really need to understand these things at a level much deeper than anyone is going to write here. There’s loads of information about them out there on the internet, they are in no way Cake-specific, so this is the wrong place to do that particular learning.

1 Like

thanks @Zuluru, you mean to say that cakephp does not provide anything websocket class by default but it provide socket for Network protocoal! thanks you clearify to me now. I have one more question if you help me please :-

Can you tell me whats wrong thing here?

If I knew how to answer that one, I would have answered that one.