Click here to Skip to main content
15,884,056 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all.
i have a winform and console in c# 2013.
i want to pipe them and send&receive data.
data means character string.
something like chat but so basic and user can't control this process.
this process must be synchronized.
they should be able to send and receive data at the same time.
'll Be happy if someone could help me.
sorry for spelling errors. i'm not english and i can't speak english good.
Posted

1 solution

Use two instances of a named pipe: one for one direction, another for another.

Now, why "sync"? A pipe is a thread synchronization primitive by yourself. Don't even try to use others (unless you share data beyond the pipes between the threads in the same application). You just unconditionally put data in the pipe. From the other side, you unconditionally read. Of course, prefer working with the pipes in a separate thread per pipe. So, just read. This is the blocking call. If the data is not available, your call will put your calling thread in a wait state: it will be switched off and never scheduled to execution, wasting no CPU during wait, until the thread is waken up. It can be waken up when data arrives, and also by some other conditions, such as timeout or thread abort.

If you use thread synchronization, it's where you use the shared data, from the pipe or not. This is a separate issue.

Now, I'm not sure you really need named pipes. You can use those pipes indirectly using "classical" .NET remoting or WCF (most likely, self-hosted on one or both sides). Both technologies use interchangeable channels, and one kind of channels is called "IPC", which is, in both cases, based on named pipes.

Besides, I cannot be sure you really need communications between two processes. Many beginners try to use more than one process for one application, underestimated the hassles of such solutions and overestimating the difficulty of merging different modules in a single-process application. Form and console? Looks weird. Shouldn't one part be a Windows Service? You did not provide any detail, but I would strongly recommend you to critically review the architecture.

[EDIT]

Thank you for clarification. I would add one more idea: if the applications are already connected via sockets through the LAN, you can do the same for connecting different applications on the same computers. This is not an overkill: actually sockets were originally developed as the ICP facility. Only later the sockets interface was extended to cover network communications. They are more flexible, and you will reuse the code.

Likewise, you can use not sockets directly, but also "classical" .NET remoting or WCF with networking channels.

Networking can be done on different level. In my past answers, you can find my short overview of them:
how i can send byte[] to other pc[^],
Communication b/w two Windows applications on LAN.[^].

—SA
 
Share this answer
 
v3
Comments
mamali-1346 13-Aug-13 21:15pm    
thank you so much dear Mr.
First I will explain about the program.
In this project there are two pcs that are connected together via LAN.
Each pc has its own specific winform app. that user can see and work with that.
and also each of them have their own specific console app that user can't see and can't work with them.
On each pcs, winform and console are connected via NamedPipe.
And two computers are connected together via consoles on the LAN networks. (Using socket programming)
Each winform send data to own console.
console insert data in own data base.
when other pc is available, two consoles exchange the data.
And finally, each consoles send data to own winform.
It is possible for the operation to happend synchronous. in fact, winform and console are chatting.
if you sure i don't need namedpipe, so what do i use?
again sorry about bad spelling and grammar. and if there are any question, ask and i tyr to answer that.
Sergey Alexandrovich Kryukov 13-Aug-13 21:33pm    
Okay, please also see my updated answer, after [EDIT].
—SA
mamali-1346 13-Aug-13 21:48pm    
so tnx
Sergey Alexandrovich Kryukov 13-Aug-13 23:40pm    
Well, will you accept the answer formally now (green button)?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900