WinForm and uwp how to communicate two-way, I used MQTT, the shortcoming is that when the amount of data sent is relatively large, there will be a very serious delay, but also try socket mode, but WinForm can not connect to uwp, which friend please help me, thank you!
-
winform and uwp are presentation layers, and MQTT is at data/transfer layer. I think they are not tightly coupled. – David Jun 01 '18 at 08:21
-
We're all presuming this is one UWP+WinForms app, and not a WinForms app on one machine and UWP app on another, correct? – Malachi Jun 01 '18 at 08:31
-
1WinForm and uwp are two separate applications running on the same computer. They need to communicate with each other and transmit data. – Values Jun 01 '18 at 08:35
-
Aha! That changes things... – Malachi Jun 01 '18 at 08:36
-
For sure something better than MQTT can be used. You probably could stuff Web API from ASP.NET Core into both, but I think there are better options than even that – Malachi Jun 01 '18 at 08:39
-
Using ASP.NET does not meet our requirements. We can not install or operate IIS on our client computers. – Values Jun 01 '18 at 08:47
-
`ASP.NET Core` is much lighter and operates fully independently of IIS – Malachi Jun 01 '18 at 09:02
-
1Thank you very much for your reply. We need to reconsider our implementation. – Values Jun 01 '18 at 09:14
-
A UWP app runs in a sandbox that forbids any kind of process interop. "Large delay" is not a problem, you can't make this work at all. Only a connection to an external server, outside of the local network, is acceptable. – Hans Passant Jun 01 '18 at 10:52
2 Answers
UWP and WinForms should be able to communicate behind the scenes with standard C# constructs. I never used UWP, but in with WPF, WPF and WinForms more or less sit in the same process space. No need for fancy interprocess communication.
That said, perhaps you could give us an idea of what data is being passed?
EDIT: After some more info, I now understand you are talking about two different apps. In the past, WCF was the go-to mechanism for this, but I think there are better options these days. I yield the answer to someone more knowledgable

- 2,260
- 3
- 27
- 40
-
1Thank you for your reply. However, in uwp, many classes, attributes and methods can not be used. For example, Accept and Receive in Socket class are not defined. The data that WinForm sends to uwp is JSON、picture data – Values Jun 01 '18 at 08:29
-
What you're interested in is a transport+serialization combo. Perhaps something like this https://johnkoerner.com/csharp/IPC-in-net-core-using-protobuf/ , or signalR (which is a fancy distant relative of Web API) – Malachi Jun 01 '18 at 08:46
-
-
Ah yeah, I forgot about that. You are at the mercy of PCL's aren't ya... – Malachi Jun 01 '18 at 09:26
-
Thank you very much for your reply. Can the two independent uwp run on the same computer communicate by socket? – Values Jun 01 '18 at 13:38
From the document Note part, two independent uwp run on the same computer can not communicate by socket.
As a consequence of network isolation, Windows disallows establishing a socket connection (Sockets or WinSock) between two UWP apps running on the same machine; whether that's via the local loopback address (127.0.0.0), or by explicitly specifying the local IP address. More about UWP apps can communicate with one another, see App-to-app communication.
Besides, you can also integrate app services into your UWP app to allow the sharing of data and functionality across apps, see the topic Use app services and extensions.
Lastly, you can also refer this similar thread:

- 3,734
- 1
- 10
- 13
-
Thank you very much for giving us a brand new idea. We will try this method seriously. Thank you. – Values Jun 04 '18 at 06:59