Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:07:38+00:00 2026-05-25T17:07:38+00:00

In a nutshell, I am trying to write a C++ XPCOM component which listens

  • 0

In a nutshell, I am trying to write a C++ XPCOM component which listens on a UDP port and calls a callback function (a javascript function) every time a UDP packet arrives.

Sorry if the answer is too obvious but I was wondering what are the ways to listen on a UDP port with Mozilla (Preferably something easy to do)?

I know that there is an interface called nsIServerSocket which allows some listeners to be attached to it, but this is only for opening TCP ports. Is there any UDP equivalent of this (where I can attach a listener which is notified every time a UDP packet arrives)?

I also know that I could probably use PR_OpenUDPSocket and such. Is there a way of using this without dealing with threads? (As far as I understand I have to return to the calling javascript function after opening the port).

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:07:38+00:00Added an answer on May 25, 2026 at 5:07 pm

    Why do you need to restrict yourself to Mozilla’s API if you are writing C++ code? You can use the POSIX socket API directly, see How to set up a Winsock UDP socket? for a WinSock example (the only difference for Linux and OS X should be that WSAStartup() call is unnecessary). nsIServerSocket is mainly useful for JavaScript code that doesn’t have the option to use the system libraries directly.

    If you prefer a straight answer to your question: no, there is no XPCOM API to create UDP sockets. You already found the NSPR API (PR_OpenUDPSocket()) but it is probably designed with DNS communication in mind since that’s pretty much the only UDP communication a browser would do. Don’t expect much here.

    And a side-note: you might want to avoid binary XPCOM components and create a native library that can be called via js-ctypes instead. See here for the details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are the specs that I'm trying to implement in a nutshell: 1) Some
Here's what I've been trying to do, in a nutshell: class example <T extends
The problem in a nutshell: This is what happens when trying to insert a
Nutshell: I launch a thread from my form, then some time later use the
In a nutshell, I'm trying to do the inverse of classObject.getDeclaredClasses() . I have
Have the following (non-straightforward) T-SQL query, which i'm trying to convert to LINQ (to
In a nutshell what Im trying to achieve is to have a re-usable DLL
In a nutshell, I want to write my own device driver for windows, so
I'm trying to use the PredicateBuilder, as described here - http://www.albahari.com/nutshell/predicatebuilder.aspx The following code
So here's what I'm trying to do in a little nutshell, I'm just gonna

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.