Calling a method from a different process C# [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want call a method accepting a string as parameter on a console application from a completely different application. Purpose of the call is simply write a line to the console window from a different application for posting some debug lines. What could be the best way to achieve this? (I have control of both application sources)

You could use anonymous pipes (on local machine) or named pipes (if you require the processes to communicate over network as well). Pipes are very common way for processes to communicate, other solutions include memory mapped file where the processes exchange messages or, and I very much discourage you to do this, a directory where messages are exchanged in form of files being created and their creation observed using FileSystemWatcher.
You can see an example of names pipes in action on How to: Use Named Pipes for Network Interprocess Communication on MSDN. The example demonstrates two processes where one of them uses NamedPipeServerStream and the consuming processes use NamedPipeClientStreams to be able to intercept the incoming messages from the server application.
Here's an example of the same thing using anonymous pipes, if you don't require the processes to work over the network.

Related

Communicate with several ports on a server using multiple threads [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I apologize for the multiple questions but I am having a hard time finding information on exactly what I am trying to do here.
Background:
I am working on a project that involves communicating with several server ports simultaneously that needs to somewhat scale. Some background on the project is I have a web application for users to pass commands to a console application. This console application will then send those commands to a specific port on a preexisting server through a tcp client.
My specific questions regard the console application communicating with the preexisting server.
My idea:
So my idea is to use a producer-many consumers thread scheme. I will need to be able to communicate with up to 300 different ports simultaneously and constantly through TCP connections. This console application will run as a windows service or something along those lines.
Question 1:
I am thinking of using a ConcurrentDictionary<string,ConcurrentQueue>() to track a queue of commands for every specific thread. Is there a better way to do this? I ask because I assume every thread would need access to the entire Dictionary of commands correct? Maybe this is a good approach but I have never done something like this.
Question 2:
Does spawning a single thread for each port I need to send commands to on the server make sense? The only reason I am thinking of doing this is because I will need to keep a TCP connection open for a very long time. The user can choose when to shut down the tool/connection. The only requirement really is this needs to be communicating for days at a time. The MOST I will reach is about 300 threads using this approach.
Question 3:
Obviously using an asynchronous approach is going to be necessary for this to scale well. Can anyone point me to some GOOD not out dated resources of the PROPER way to implement something like this asynchronously. I am willing to even pay for a book / online course if you have a good recommendation. The Microsoft docs are not very helpful because they do a scheme of 1 send and 1 read and then close the tcp connection.

How to share data between programs that use different languages to run [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to share data between programs that run locally which uses different languages, I don't know how to approach this.
For example, if I have a program that uses C# to run and another that uses python to run, and I want to share some strings between the two, how can I do it?
I thought about using sockets for this but I'm not sure that this is the right approach, I also thought about saving the data in a file, then reading the file from the other program, but, it might even be worse than using sockets.
Note that I need to share strings almost a thousand times between the programs
There are a lot of ways to do so, I would recommend you reading more about IPC (Inter Process Communication) - sockets, pipes, named pipes, shared memory and etc...
Each method has it's own advantages, therefore, you need to think about what you're trying to achieve and choose the method that fits you the best.
Any kind of IPC (InterProcess Communication) — sockets or shared memory. Any common format — plain text files or structured, JSON, e.g. Or a database.

Windows services c# to send its data to c# wpf Application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a question regarding a Windows C# services.
Is it possible for the window service to run in background and send/Receive its data to a C# standalone application with opened by a user. if so how is it that it can be done?
Is there any other better ways for building a window service
Yes this can be done, and there are several options. For inter-process communication - which is basically what you are asking for - you could consider WCF with NamedPipes or TCP, or a message queue (MSMQ, RabbitMQ etc).
Typically with a message queue the messages will queue if the service or client is not there, or with named pipes or TCP a current connection must be available.
WCF named pipe minimal example
Yes, it's possible. You can run a service like windows service, expose methods, and one or more client can use it.
One example is this.
Bye bye.

In C#, How do I monitor what goes in and out my ip sockets that other programs are using? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Trying to make console app that monitors alongside its main program, and monitors what the main program has going in and what goes out its tcp/ip sockets. I have seen people do this in a few programs, but I can't figure out how. Something about using a raw socket, but I am not sure.
Any ideas how?
If you want the console app to be entirely separate from the main program, you can do this various ways:
Create a man-in-the-middle proxy for the connections. Run a client and server socket from your console application - i.e. clients connect to your proxy server and then your proxy server will forward the connection to your main program. This allows you to record the packets on their way through your console.
Hook winsock.dll. Essentially you will be gaining access to the parameters of send() and recv() calls that your main program makes, and you can then output or do as you like with it.
Forget programming it, and use Wireshark or another network sniffer to check what's going in or out.
More information on number 2:
It was surprisingly difficult to find good tutorials in C#, mainly because it's generally done with C++ or C. Some links to get you started:
https://en.wikipedia.org/wiki/Hooking
http://csns.calstatela.edu/download.html?fileId=2062150
http://www.elitepvpers.com/forum/co2-programming/1917917-c-dll-injecting-hooking.html
A tool to assist with hooking: http://easyhook.codeplex.com
I'll update this list as I find better resources. I might make a tutorial myself, will keep you informed.

Adding external callable api to program C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to create a simple application that is only supposed to be called by other applications. I've taken the concept from linux where you often have a application that depends on another, and then it does api-calls to that other application. The example I'm thinking about is libnotify which enables for notification of messages with or without image and title (this can for instance be found in ubuntu linux > 9.04). And then somebody created a plugin for pidgin that when you receive a message call the libnotify-"program" to display the notification, instead of building it's own notification-method.
Well, this is more or less what I want to create myself, but on windows. I've created a application that displays notifications (sort of like msn does on new message), and then I want to create for instance facebook-notifications that whenever it need to notify anything it will just call my notification-program. I've thought about making the all the specific parts as plugins (like a facebook plugin, and a twitter plugin), but then I have to load the external dlls into my already running program, and I rather like that the other programs can just call on the first one.
Any help or thoughts on the subject would be appreciated.
This is what DLLs are meant for.
Make your notification code into a DLL with a public class that displays the notification. You can then make other programs that reference the DLL and use the class.
You can use:
WCF
COM
Web Services
Run separate Process
Sockets
Named Pipes
Basically any inter-process communication.
But the easiest would be to simply reference a dll.
You can make a Web Service and have it reside on a central server while all your applications have access to it.
Here is a sample web service: http://www.codeproject.com/KB/webservices/myservice.aspx

Categories