C
C#14mo ago
Tim

✅ Pipe client server

Hey! I've been reading into the C# Pipe stream stuff, because I need some interprocess communication. What I want is 2 processes being able to send a bit of data to each other whenever. All the example's I've seen so far just - Open a stream - Send some data - Recieve some data back - Close the stream Can somebody point me in the right direction on how to do more long lived communication? If I want to support recieving and sending at the same time, do I need multiple Streams per program?
10 Replies
Tim
TimOP14mo ago
Or, do I connect a new Client and server everytime I want to send something?
cap5lut
cap5lut14mo ago
in the end they work more or less like any other stream once the connection is established. so u can have async tasks that simply read the next packet on the event and raise some kind of event ur application can react to and completely unrelated to that u can also simply send packets
Tim
TimOP14mo ago
So, they Read and Write operations don't interfere? For example if the server writes a buffer and then the client writes a buffer they are separate?
cap5lut
cap5lut14mo ago
yep, they do not interfer
SiloCitizen3
SiloCitizen314mo ago
Check out https://www.youtube.com/watch?v=E0Ld7ZgE4oY Maybe not. Sorry, I read your original post as INprocess not INTERprocess
Raw Coding
YouTube
C# Channels Explained (System.Threading.Channels)
In this c# channels tutorial I answer the questions: what is a channel? how does a channel work? how to use a channel? when to use a channel? what problem does a channel solve? Contents: 1. Basic problem that would require shared state to improve.
2. Simple custom implementation of channels. 3. Real World Example of Channels in ASP.NET Core ...
SiloCitizen3
SiloCitizen314mo ago
it covers System.Threading.Channels, which I think it what you want
Tim
TimOP14mo ago
Yeah indeed between processes Ah great, that makes more sense So, then I'm gonna run a thread that listens for incoming data and calls events based on that Is it safe to (while that thread is running) also write to the same stream?
cap5lut
cap5lut14mo ago
yep
Tim
TimOP11mo ago
🎉 Thanks! Will close when I get the implementation down Seems this is incorrect I only just now started implementing two way messaging But you cannot actually send and receive at the same time Since internally the stream uses the same handle for sending and receiving If you are sending data, calling any functions to receive data will result in a broken stream exception I'm probably gonna use 2 different pipe streams to mitigate this
cap5lut
cap5lut11mo ago
hey, i looked at some old code that was used, they did indeed use 2 streams under the hood. sorry for the misinformation 😒
Want results from more Discord servers?
Add your server