Silverlight communication with a desktop process - silverlight

If there was a process on the user's desktop, would Silverlight be able to communicate with it? Is there a way to send messages from SL to a process that runs in the background and vice versa?
P.S. I am particularly interested in non-OOB SL.

Running OOB, with Elevated Trust would allow to open a socket connection to arbitrary destinations, including a local process hosting a listen socket. Otherwise I see no way how to do it.

No. Silverlight will not allow you to deal with anything outside the web browser in non-OOB.

Silverlight -> JavaScript -> ActiveX
http://forums.silverlight.net/forums/p/17053/206880.aspx

Related

Google hangout desktop application flow

I am creating a screensharing application that would work in a similar manner like Google Hangout Screen Shares, and I'd like to know how the Google Talk plugin (used for Screen Shares) spawns child processes and uses a dynamic port range.
I am creating a background running application that user will have to install, and which talks with browser like how they describe here, http://www.codeproject.com/Articles/36517/Communicating-from-the-Browser-to-a-Desktop-Applic
But when I look at googleTalkPlugin, which is responsible for google hangout screen sharing, I saw that there are a lot of processes running, and whenever I open a new browser, a new talk plugin for that browser starts, as child service.
Here are some snapshots
and when I noticed the port used by googleTalkPlugin, I came to know its dynamic! If you saw the above link, the Browser Desktop communication is on static port.
I am very interested in knowing, how do I use dynamic port numbers? Also, should I create child process for every browser?
Or something better?
The reason there is a separate child process for each browser is that the Google Talk application is implemented as a browser plugin. Each browser has a Google Talk plugin installed and doesn't know about the other browsers, their plugins or their subprocesses. Each browser will launch the plugins that it has installed and, as Eduard mentioned in the comments, some plugins are started in a separate process. This isn't behavior that is special about Google Talk, it is behavior you will see with most plugins. If you implement your application as a browser plugin you will have the same behavior. If you don't want your application to run as a subprocess of a browser then you will need to write it as a standalone application, not a browser plugin.
If you want to learn more about spawning subprocesses read up on fork(). There are lots of other good resources around the internet on subprocesses.
Your other question is around dynamic port numbers. The easiest way to do this is to bind to port 0 and you will be assigned a random open port by the operating system. You can then use getsockname() to find out what port you ended up with. If you are working with a client/server situation you can have the client do this and then just tell the server which port it is using.

bittorrent client within silverlight

Is it possible to make bittorrent client within silverlight, which will run in browser?
this would be unusual bittorrent client, he will download data from the server and will seed it. is it possible to do?
Is it possible to do within different, web tech, such as e.g. JavaFX?
Yes, completely possible. You can't receiving incoming connections, but that's no requirement for Bittorrent. The only thing that makes it difficult is that the peers you are connecting to need to serve a socketpolicy file on port 80 or 943, and almost none of them do. Without this policy, the Siverlight BT client will only work in the trusted 'Out of browser'-mode, which make it less usefull.
It's like a chicken-egg problem: as long as their is no large userbase for a Silverlight BT client, 'normal' nodes will not open port 943, and without that port, there never will be a large userbase for such an client.
Adobe solved this smartly by introducing Cirrus, their hosted rendezvous routing service which makes P2P possible from Flash without torrents.
No. You don't have access to the client's file system outside sandbox access.
http://betaforums.silverlight.net/forums/p/9351/29437.aspx

Silverlight c# socket

Has anyone gotten a silverlight socket application to run successfully over the internet? Like have a console server that listens for client. The client uses silverlight sockets where users can go on any web browser and connect to the console server.
Out-of-browser applications in Silverlight 4 work with sockets just fine. Our SecureBlackbox product offers implementations for various protocols (HTTPS, FTPS, SSH/SFTP, SSL/TLS) over Silverlight socket, and they work just fine. If you want to have something in browser, you need to make/modify the server to (a) listen on the port that belongs to specific port range (4502 to 4534) and (b) accept requests on another port 943 and provide a policy file. For more information about these requirements see Microsoft document.
While I haven't had the chance or need to do so, a user group meeting I attended covered just this topic. You can watch the video of the presentation here and a copy of the code sample here.
Try example from "Pro silverlight 4 with c#" or "Pro silverlight 3 with c#". It can be downloaded from Apress.
I have used exaple for silverlight 3 and it works fine.

Alternative to SendKeys when running over Remote Desktop?

I have an application which injects keystrokes into applications via SendKeys.
Unfortunately, the application will not work when I am running it via Remote Desktop
because of the well known issue that SendKeys doesn't work with Remote Desktop.
Has anyone solved this issue before, or have any good suggestions on how to resolve it?
SendKeys is not a good fit mainly due to:
It can only send keys to active/focused application, which is never guaranteed to work because the the active application can change between the time the keys are actually sent.
RDP and many other libraries (e.g., DirectX) block them mainly for security reasons.
Better alternatives:
Use SendMessage or SendInput for simple needs
Some good examples of how to use SendMessage can be found:
Send strings to another application by using Windows messages
SendMessage via pInvoke
How To Send Keystrokes To Extern Win Application
For more elaborate needs, it is recommended to use WCF
To get you started, read this Basic Tutorial that talks about Inter Process Communication
Sample code using SendMessage:
HWND hwndNotepad = FindWindow(_T("Notepad"), NULL);
HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, _T("Edit"), NULL);
SendMessage(hwndEdit, WM_SETTEXT, NULL, (LPARAM)_T("hello"));
In my case I was successfully using WinAPI's SendInput with hardware scan codes. It seems like SendKeys maps chars to scan codes incorrectly.
You can workaround RDP issue by having desktop always logged in before use (or configured for auto-login # every boot).
And even with the auto-login, if you ever need remote desktop access to run automation, or manage system, etc., the preferred method is using VNC for remote access rather than RDP. Reason is VNC is cross platform and you won't run into this RDP issue. VNC works like a relay of your actual desktop (RDP console session 0 or the "head" of the machine), the disadvantage being one remote session at a time only (or you all share the same desktop + keyboard + mouse). VNC will work for virtual machines too. Use VNC instead of RDP or local (RDP) access from the (VMWare/Hyper-V/Xen) virtual machine manager software.
The only thing to watch out for with VNC still is that the desktop not be configured to auto-lock on idle or screensaver, that may also stop send keys and GUI automation from running, so be sure to disable that. Screensaver & monitor power save is ok, just no auto-lock & password protect.
NOTE: I'm not sure, but believe since VNC relays the desktop "as is", it is the same as executing locally from the app/system's point of view, so it should in theory also be able to fool the system/app that doesn't allow SendKeys via RDP. I've had no issues using this VNC method for AutoIt + SendKeys, whether I was actively connected via VNC, or disconnected (sendkeys/automation still continues to work after disconnect because on the actual desktop, it's still logged in, just that VNC not active).
In my case I was using sendkeys as part of test automation. It would not work from my build machine, where the build agent runs through remote desktop protocol. I'm not happy about it but I was able to skip that test as part of my automated builds.
Using Win32 calls to send window messages might work, if I have time I may try that someday.
Anyhow, here is the check to see if the current code is running in a remote desktop session:
System.Environment.GetEnvironmentVariable("SESSIONNAME").StartsWith("RDP-")

Accessing Local Devices from Web Page/Application

I am designing an application that requires me to access devices connected to the machine. We will have control of the machine, meaning control of the software and OS installed.
I know in the past one might suggest active-x controls, I was wondering is there a better solution? I have looked into Silverlight as an alternative, but not found much information supporting that design approach
Well, in theory, there's tcp support in Silverlight and so you could use that to talk to a local piece of software. In reality, tcp won't connect to the local machine unless you're in debug mode. So, that's a problem.
What people have been doing is creating a local WCF service and communicating with that. If you take this approach, don't forget to host up a cross-domain file as well.
I'd just add that if you can control what's on the client machine, WPF may be a much more straightforward answer :)
If you are speaking of the client's machine, Silverlight will not be of much help since it is sandboxed. In fact browsers and plugins are so locked down, that I think you should change your approach (maybe deploy your own client app, instead of using a browser/web app?)

Resources