问题
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