8

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

when I started safari

when I started firefox

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?

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
Hitesh Joshi
  • 724
  • 8
  • 19
  • Not sure what you mean. Why a child process for every browser? – Prof. Falken May 15 '13 at 06:24
  • because thats what google talk plugin does. As you can see images, a new child process for every browser is raised when that browser is running. – Hitesh Joshi May 15 '13 at 09:47
  • 4
    I think that is because Chrome has a process for every tab. – Prof. Falken May 15 '13 at 09:49
  • And what about firefox and safari process you can see in above pics? And what if user dont have chrome? so google hangout should not work in that system? which is not the case. – Hitesh Joshi May 15 '13 at 09:52
  • 1
    Firefox starts some plugins in a separate process: http://support.mozilla.org/en-US/kb/What%20is%20plugin-container Chrome starts a new process for each tab. Those are the processes you see. The hangout plugin does nothing special. Anything more you need to know? – Eduard Wirch May 15 '13 at 13:42
  • Eduard! Thanks for the link. But if you can see in above pics, the highlighted blue area has child process for each browser (not each tab) and that process is linked to Google Talk. for instance, When I start firefox, a new process named. Firefox Plugin Process(Google Talk Plugin) starts. – Hitesh Joshi May 15 '13 at 14:46

1 Answers1

2

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.

seanmk
  • 1,934
  • 15
  • 28