Native messaging, re: re-establishing a connection with host application after close

北城以北 提交于 2019-12-25 02:57:12

问题


I have a functioning extension that communicates with native host C# app. Looking for a way to automatically re-establish a connection with the C# app after I close and re-open it. Any help greatly appreciated.


回答1:


Native messaging means only Chrome can start a host instance when it "connects". It's a misnomer, since connect() means "launch a new copy and talk to it".

There is no way to "attach" to an already-running process. If you close the host, stdio pipe is broken the Port object fires onDisconnect event. Then you need to re-launch the host from the extension to be able to talk to it.




回答2:


How about asking the server if it's still here (i.e. once every 30 seconds)

if you get no answer given a certain delay (=> timeout) drop the connection and create a new one.

Th delay must not be too fast, to avoid resettong connections when there is only a 'lag spike'



来源:https://stackoverflow.com/questions/29705852/native-messaging-re-re-establishing-a-connection-with-host-application-after-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!