473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Send message to .Net process

I am searching for a solution of sending messages from not .Net process into
a .Net process written in C#.
I have gone already thru sockets solution and have porblems with it. I am
not a C# coder dont kill :)
I am thinking about something like this:
A remote non .Net process has a window with a name known to .Net program.
Can .Net program somehow process that window using window's title and
extracting a text from it?
What other solutions might be?

Thanks
Aug 15 '08 #1
5 9693
You are looking for IPC:

http://msdn.microsoft.com/en-us/libr...74(VS.85).aspx

Most likely Named Pipes will do what you want.
Aug 15 '08 #2
On Fri, 15 Aug 2008 13:35:25 -0700, Markgoldin <ma*************@yahoo.com>
wrote:
I am searching for a solution of sending messages from not .Net process
into
a .Net process written in C#.
I have gone already thru sockets solution and have porblems with it. I am
not a C# coder dont kill :)
I am thinking about something like this:
A remote non .Net process has a window with a name known to .Net program.
Can .Net program somehow process that window using window's title and
extracting a text from it?
Using unmanaged code, there are ways to identify windows for other
processes and manipulate them. But that would involve information flowing
_from_ the .NET process to the non-.NET process, which is the opposite of
what you've asked.

Using sockets would in fact be a reasonable solution, as would named pipes
as James suggests (my understanding is that .NET 3.5 includes support for
named pipes now). But you're not specific about why you "have problems
with it". It's impossible to provide any advice along those lines without
details about what problems you specifically had.

Pete
Aug 15 '08 #3
On Aug 15, 11:35*pm, "Markgoldin" <markgoldin_2...@yahoo.comwrote:
I am searching for a solution of sending messages from not .Net process into
a .Net process written in C#.
I have gone already thru sockets solution and have porblems with it. I am
not a C# coder dont kill :)
I am thinking about something like this:
A remote non .Net process has a window with a name known to .Net program.
Can .Net program somehow process that window using window's title and
extracting a text from it?
What other solutions might be?

Thanks
If you want to understand the hole communication between process and
thread read the book of Jeffrey Richter
You have the import one of this functions depends on your need
PostMessage Or SendMessage

Bast Regards
Ohav Baumgarten
Aug 15 '08 #4
Here is my complete project:
main class:

using System;
using System.Net.Sockets;
using Lightstreamer.DotNet.Server;
using System.Net;
using System.Threading;
public class DataAdapterLauncher
{
public static TcpListener tcplJM4;
public static TcpListener tcplJM5;
public static TcpListener tcplJM6;
public static TcpListener tcplMD1;
public static TcpListener tcplMD2;
public static TcpListener tcplJM1;
public static TcpListener tcplJM2;
public static TcpListener tcplG2;
public static TcpListener tcpl1;
public static void Main(string[] args)
{
string host = "localhost";
bool go = true;
int reqrepPort = 6661;
int notifPort = 6662;
try
{
DataProviderServer server = new DataProviderServer();
server.Adapter = new SocketToLightStreamer();

MetadataProviderServer serverMeta = new
MetadataProviderServer();
serverMeta.Adapter = new MessageAwareLiteralBasedProvider();

TcpClient reqrepSocket = new TcpClient(host, reqrepPort);
server.RequestStream = reqrepSocket.GetStream();
server.ReplyStream = reqrepSocket.GetStream();

TcpClient notifSocket = new TcpClient(host, notifPort);
server.NotifyStream = notifSocket.GetStream();

server.Start();
System.Console.WriteLine("Remote Adapter connected to
Lightstreamer Server.");
System.Console.WriteLine("Ready to publish data...");

//start listeners that send data to the front-end. One for each
scanning area
IPEndPoint ipeJM4 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63335);//listen on all local addresses
tcplJM4 = new TcpListener(ipeJM4);
tcplJM4.Start(); // block application until data and connection
is requested
IPEndPoint ipeJM5 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63336);//listen on all local addresses
tcplJM5 = new TcpListener(ipeJM5);
tcplJM5.Start(); // block application until data and connection
is requested
IPEndPoint ipeJM6 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63337);//listen on all local addresses
tcplJM6 = new TcpListener(ipeJM6);
tcplJM6.Start(); // block application until data and connection
is requested
IPEndPoint ipeMD1 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63339);//listen on all local addresses
tcplMD1 = new TcpListener(ipeMD1);
tcplMD1.Start(); // block application until data and connection
is requested
IPEndPoint ipeJM1 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63338);//listen on all local addresses
tcplJM1 = new TcpListener(ipeJM1);
tcplJM1.Start(); // block application until data and connection
is requested
IPEndPoint ipeJM2 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63340);//listen on all local addresses
tcplJM2 = new TcpListener(ipeJM2);
tcplJM2.Start(); // block application until data and connection
is requested
IPEndPoint ipeG2 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63342);//listen on all local addresses
tcplG2 = new TcpListener(ipeG2);
tcplG2.Start(); // block application until data and connection
is requested
IPEndPoint ipeMD2 = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
63341);//listen on all local addresses
tcplMD2 = new TcpListener(ipeMD2);
tcplMD2.Start(); // block application until data and connection
is requested
catch (Exception e)
{
System.Console.WriteLine("Could not connect to Lightstreamer
Server.");
System.Console.WriteLine("Make sure Lightstreamer Server is
started before this Adapter.");
System.Console.WriteLine(e);
}
}
}

and another class:

using System;
using System.Collections;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;

using Lightstreamer.Interfaces.Data;

public class SocketToLightStreamer : IDataProvider
{
private IItemEventListener _listener;
private volatile bool goJM4;
private volatile bool goJM5;
private volatile bool goJM6;
private volatile bool goMD1;
private volatile bool goJM1;
private volatile bool goJM2;
private volatile bool goMD2;
private volatile bool goG2;

public void Init(IDictionary parameters, string configFile)
{
}

public bool IsSnapshotAvailable(string itemName)
{
return false;
}

public void SetListener(IItemEventListener eventListener)
{
_listener = eventListener;
}

public void Subscribe(string itemName)
{
if (itemName.Equals("floorupdate"))
{
new Thread(delegate() { Run(goJM4,
DataAdapterLauncher.tcplJM4); }).Start();
new Thread(delegate() { Run(goJM5,
DataAdapterLauncher.tcplJM5); }).Start();
new Thread(delegate() { Run(goJM6,
DataAdapterLauncher.tcplJM6); }).Start();
new Thread(delegate() { Run(goJM1,
DataAdapterLauncher.tcplJM1); }).Start();
new Thread(delegate() { Run(goJM2,
DataAdapterLauncher.tcplJM2); }).Start();
new Thread(delegate() { Run(goMD1,
DataAdapterLauncher.tcplMD1); }).Start();
new Thread(delegate() { Run(goMD2,
DataAdapterLauncher.tcplMD2); }).Start();
new Thread(delegate() { Run(goG2,
DataAdapterLauncher.tcplG2); }).Start();
}
}

public void Unsubscribe(string itemName)
{
if (itemName.Equals("floorupdate"))
{
goJM4 = false;
goJM5 = false;
goJM6 = false;
goMD1 = false;
goMD2 = false;
goJM1 = false;
goJM2 = false;
goG2 = false;
}
}

public void Run(Boolean go, TcpListener tcpl)
{
go = true;
// Buffer for reading data
Byte[] bytes = new Byte[1024];
String data;
Encoding ascii = Encoding.ASCII;
TcpClient tcpc = null;
while (go)
{
if (tcpc == null)
tcpc = tcpl.AcceptTcpClient(); //accept connection
data = "";
NetworkStream stream = tcpc.GetStream();
// Loop to receive all the data sent by the client.
int i = 0;
i = stream.Read(bytes, 0, bytes.Length);
while (i 0 && !data.EndsWith("\r"))
{
// Translate data bytes to a ASCII string.
data += ascii.GetString(bytes, 0, i);
i = stream.Read(bytes, 0, bytes.Length);
}
// Process the data sent by the client.
if (data != "")
{
if (data.IndexOf("close") != -1)
{
System.Console.WriteLine("Closing connection ...");
go = false;
tcpl.Stop();
tcpl.Start();
new Thread(delegate() { Run(go, tcpl); }).Start();
return;
}
else
{
System.Console.WriteLine(data);
IDictionary eventData = new Hashtable();
eventData["scan"] = data;
_listener.Update("floorupdate", eventData, false);
}
}
}
}
}

Three problems with.Net side:
1. Sometimes it crashes
2. when a client is disconnected CPU on a box that run this console
application goes to 100%.
I am trying to handle that with this:
....
if (data.IndexOf("close") != -1)
{
System.Console.WriteLine("Closing connection ...");
go = false;
tcpl.Stop();
tcpl.Start();
new Thread(delegate() { Run(go, tcpl); }).Start();
return;
}

3. I am missing some readings from sockets. I think that is due to this:
.....
else
{
System.Console.WriteLine(data);
IDictionary eventData = new Hashtable();
eventData["scan"] = data;
_listener.Update("floorupdate", eventData, false);
}

I am thinking to move that into a separate thread. Do you think it will
help?

Just want to remind I am not a c# coder. So dont kill if you see something
funny :)
Aug 19 '08 #5
On Tue, 19 Aug 2008 10:46:04 -0700, Markgoldin <ma*************@yahoo.com>
wrote:
Here is my complete project:
Surely whatever problems exist in your code, they could be demonstrated
with just one TcpListener, rather than nine. Or, in other words, the code
you posted isn't a "concise-but-complete" code sample, which is the usual
standard for posting code when you want someone else to find problems in
it.

So, keeping in mind that I haven't put a lot of effort into examining each
and every line of code you posted...
[...]
Three problems with.Net side:
1. Sometimes it crashes
That's too vague a problem description for anyone to help. What does
"crash" mean? Does the OS actually terminate the process? Is there an
error or exception? If so, what is it?
2. when a client is disconnected CPU on a box that run this console
application goes to 100%.
Ahh...this seems familiar. I'm guessing this is the network code you had
questions about previously?

As far as the #2 question goes, you have some irregularities in your
SocketToLightStreamer.Run() method, but the one that is causing the CPU
consumption is that after the stream is closed (Read() returns 0), you
should set your TcpClient variable back to null.

It's not a great way to control flow within the loop, but that should at
least fix that issue, without having to resort to:
I am trying to handle that with this:
...
if (data.IndexOf("close") != -1)
{
System.Console.WriteLine("Closing connection ...");
go = false;
tcpl.Stop();
tcpl.Start();
new Thread(delegate() { Run(go, tcpl); }).Start();
return;
}
As before, I still fail to see the point in having a variable (named "go")
to control the loop. Especially as you set it to "true" as the first
thing in the Run() method and the only other place it ever gets set to
"false" is shortly before a "return" statement, what's the point?

Also, stopping and starting the TcpListener is pointless, and could in
fact cause issues because of the way that the OS deals with TCP listening
sockets (you may find that the port you're trying to use is unavailable
for a short time after having closed the listening socket, which is what
TcpListener does implicitly).

But the main question is: are you sure that a closed connection will have
written the text "close" to the stream before it is closed? Assuming that
it does, then I don't see why the above wouldn't work, even if it is a bit
clumsy. So it seems that the most likely explanation for your high CPU
utilization issue is that the stream doesn't have the text "close" in it
before it's actually closed.
3. I am missing some readings from sockets. I think that is due to this:
....
else
{
System.Console.WriteLine(data);
IDictionary eventData = new Hashtable();
eventData["scan"] = data;
_listener.Update("floorupdate", eventData, false);
}

I am thinking to move that into a separate thread. Do you think it will
help?
Honestly, the last thing I think that would help is _more_ threads. :)

But regardless, the code above doesn't appear to me to have anything to do
with the socket i/o at all. As near as I can tell, it's just how you're
passing the most-recently-received data to your IItemEventListener
implementation. So I don't think any modification of that section of
code, whether putting it in a new thread or something else, would help
whatever the "missing some readings from sockets" problem is.

All that said, there's really no real diagnostics that anyone can do with
respect to your code without a concise-but-complete code sample. For
network code, that means code for both ends of the TCP connection, along
with some predefined data demonstrating how the network connection is used.
Just want to remind I am not a c# coder. So dont kill if you see
something
funny :)
Just to be clear: we may harass, laugh at, or otherwise bother someone who
posts funny code (though normally we just try to help), but there's a
strict no-kill policy around here. As far as I know, no one has ever
actually lost their life because of something they posted here. :)

Pete
Aug 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kurda Yon | last post by:
Sorry for a very stupid question. Can you tell me what does the following html source does if I press button "Send"? If I read this code by Netscaspe from my local file system and then press...
3
by: Ed Sutton | last post by:
How can I show the email client UI so the user can send the attachment to the desired recipient. I get an exception if I leave the MailMessage.To property blank. Is there any way to do this? I...
5
by: Go Perl | last post by:
Hello Here is an interesting question which I could not solve it. I have an old dos app for which source code is lost. I just have the exe file. So I have created a front-end for that. I...
3
by: SenthilVel | last post by:
how to send message using net send in c#??
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
6
by: ShieldsJared | last post by:
Hello all, I've been working on an application for a while now and have now come to a standstill. I have an application that I intend to have stored on a file server (developed in C#), which...
2
by: Mesan | last post by:
Hello everyone, Thanks to many useful posts in this newsgroup and others, I've been able to come very close to something I've been wanting to do for a very long time. I've figured out how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.