public void SendAndGetResponse() { "发送消息到另一个 IPC 服务,可以等待收到对方的返回值".Test(async() => { var ipcAName = Guid.NewGuid().ToString("N"); var ipcBName = Guid.NewGuid().ToString("N"); var requestByteList = new byte[] { 0xFF, 0xFE }; var responseByteList = new byte[] { 0xF1, 0xF2 }; using var ipcA = new IpcProvider(ipcAName); using var ipcB = new IpcProvider(ipcBName, new IpcConfiguration() { DefaultIpcRequestHandler = new DelegateIpcRequestHandler(c => { Assert.AreEqual(ipcAName, c.Peer.PeerName); c.Handle = true; var span = c.IpcBufferMessage.AsSpan(); Assert.AreEqual(true, span.SequenceEqual(requestByteList)); return(new IpcHandleRequestMessageResult(new IpcRequestMessage("Return", new IpcBufferMessage(responseByteList)))); }) }); ipcA.StartServer(); ipcB.StartServer(); var bPeer = await ipcA.GetAndConnectToPeerAsync(ipcBName); // 从 A 发送消息给到 B 然后可以收到从 B 返回的消息 var response = await bPeer.GetResponseAsync(new IpcRequestMessage("发送", new IpcBufferMessage(requestByteList))); Assert.AreEqual(true, response.AsSpan().SequenceEqual(responseByteList)); }); }
private static async Task?BaiqealawbawKeqakeyawaw() { var ipcProvider = new IpcProvider(); ipcProvider.PeerConnected += (sender, proxy) => { }; var peer = await ipcProvider.GetAndConnectToPeerAsync(IpcContext.DefaultPipeName); Console.WriteLine($"连接上{peer.PeerName}"); }
private static async Task?FagurhaircerenaJawehefeljeane() { // 会断开的一端 var ipcProvider = new IpcProvider(); ipcProvider.PeerConnected += (sender, proxy) => { }; var peer = await ipcProvider.GetAndConnectToPeerAsync(IpcContext.DefaultPipeName); await peer.IpcMessageWriter.WriteMessageAsync("林德熙是逗比"); await Task.Delay(TimeSpan.FromSeconds(1)); ipcProvider.Dispose(); }
private async void ConnectToPeer(string peerName) { var peer = await IpcProvider.GetAndConnectToPeerAsync(peerName); AddPeer(peer); }