本地ubuntu设备如何监听部署在远程服务器上的Laravel应用程序的事件

本地ubuntu设备如何监听部署在远程服务器上的Laravel应用程序的事件

问题描述:

Remote Application (the App) is stored at a remote web server with static IP address and available via http/https protocol. The App uses Laravel framework.

Clients are stored at different local ubuntu devices (RaspberryPi), has internet access with dynamic ip. This clients are responsible for hardware managing. Currently, this clients use pure php and some bash scripts.

Clients interacts with the App in the following ways:

  1. requests tasks from the App
  2. sends data to the App (results of hardware management)

Both 1st and 2nd tasks could be resolved by http request.

But for the 1st task is better to use some event based solution: the app trigger events, only after that clients shall start doing tasks with immediately.

For web applications we can use websocket. But our devices has no graphic interface, just ubuntu server with command line interface.

Are there any event's based, web socket's like solutions or ideas how these clients could interact with the App?

远程应用程序(应用程序)存储在具有静态IP地址的远程Web服务器上,可通过http / https协议获得 。 该应用程序使用Laravel框架。 p>

客户端存储在不同的本地ubuntu设备(RaspberryPi),具有动态IP的Internet访问权限。 该客户负责硬件管理。 目前,这个客户端使用纯PHP和一些bash脚本。 p>

客户端通过以下方式与应用程序交互: p>

  1. 请求 来自App的任务 li>
  2. 将数据发送到应用程序(硬件管理的结果) li> ol>

    第1和第2任务都可以通过以下方式解决 http请求。 p>

    但是对于第一个任务,最好使用一些基于事件的解决方案:app触发事件,只有在客户端立即开始执行任务之后才会触发事件。 p>

    对于Web应用程序,我们可以使用websocket。 但我们的设备没有图形界面,只有带命令行界面的ubuntu服务器。 p>

    是否有任何基于事件的,Web套接字的解决方案或想法,这些客户端如何与App交互? p> div>

After looking for solutions I've found out that these kind of tasks could be resolved by using web hooks.

But, local devices don't have direct public entrance.

This issue could be resolved by using ssh tunnel between local clients and some remote server with public access. To establish this tunnel you have to run following command on your local client:

ssh -R 8010:localhost:8020 -nvNT remoteusername@remotehost

8020 - local client port to receive web-hooks, 8010 - remote server port, -nvNT - set of options to get real-time log.

During the time of this tunnel is running all requests to remotehost:8010 will be handled by local client at it's localhost:8020 port.

So then, the app could push web-hooks trough the tunnel to the client.

Bellow are a few useful links:

https://hackernotes.io/simple-recipe-forwarding-webhooks-local-development-environment/

https://www.davidokwii.com/how-to-ssh-into-server-that-has-no-public-ip-from-anywhere/

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04