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 9102783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:27:49+00:00 2026-06-17T01:27:49+00:00

Trying to use TCP sockets using chrome.socket API on Chrome Version 25.0.1364.5 dev. Looking

  • 0

Trying to use TCP sockets using chrome.socket API on Chrome Version 25.0.1364.5 dev.

Looking at the documentation for the chrome.socket.read there doesn’t seem to be a way to get a notification when new data is available to be read.

There is some sample code for a TCP server which polls the read command every 500ms but I think this would not be efficient / accurate

// Start polling for reads.
setInterval(this._periodicallyRead.bind(this, socketId), 500);

What’s more confusing is that in the ‘Network Communications’ Documentation under section ‘Receiving data’, it is stated that a special handler can be passed as an onEvent option in chrome.socket.create

The parameter is an object with one value ‘onEvent’ that is a function reference to the method that will be called when data is available on the port.

This onEvent parameter would be used like this

chrome.socket.create(
    'udp', '127.0.0.1', 1337, 
    { onEvent: handleDataEvent }, // <-- call this when new data is available
    createHandler
)

But this appears to apply only for UDP connections as I get the following error when I try to use it

Error: Invocation of form 
       socket.create(string, string, integer, object, function) 
       doesn't match definition 
       socket.create(string type, optional object options, function callback)

        at Object.normalizeArgumentsAndValidate (schemaUtils:119:11)
        at Object.<anonymous> (schema_generated_bindings:301:32)
        at chrome-extension://obljaojhdffbpcdfbeoiejegaodfoonp/background.js:11:15
        at chrome.Event.dispatchToListener (event_bindings:387:21)
        at chrome.Event.dispatch_ (event_bindings:373:27)
        at dispatchArgs (event_bindings:249:22)
        at Object.app.runtime.onLaunched (app.runtime:116:7)
        at Object.chromeHidden.Event.dispatchEvent (event_bindings:255:35) 

So the question is, can something like this be achieved with TCP Connections ? Instead of having to poll the read method every x milliseconds ?

Update

This is a workaround I am using until better documentation / event support exists.

function onReadHandler(readInfo) {
     // do things with data
     // ....

     // re register handler with callback itself
     chrome.socket.read(socketId,null,onReadHandler);         
}

chrome.socket.read(socketId,null,onReadHandler);
  • 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-06-17T01:27:50+00:00Added an answer on June 17, 2026 at 1:27 am

    For TCP connections, the callback passed to socket.read will only be executed when there is new data available. The sample code mentioned was fixed to only use the callback instead of the setInterval.

    The Network documentation is indeed outdated and we are working hard to update it. If you want to avoid the risk of outdated docs during these days of quickly changing APIs, you should always check the API reference docs – those are generated directly from the code and don’t need editorial work. If you are feeling “hacky” 🙂 you can also look directly at the Chromium source code API definitions (this one is for the socket API)

    Last, but not least, for Sublime Text users, there is a Sublime Chrome Apps and Extensions plugin. It’s not finished yet, but you can already get code completion, CSP validation and some boilerplates for bootstrapping. Install it through the Sublime Package Manager.

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

Sidebar

Related Questions

I'm learning to use raw sockets, and im trying to prase out the tcp
I am trying to use non-blocking TCP sockets. The problem is that they are
I am trying to use a TCP socket to communicate a shared state between
I'm trying to use select on STDIN and a TCP socket in Ruby, but
I am trying to use the SmallSockets library to create a TCP socket connection.
I'm trying to use Moles to mock the Socket class in System.Net.Sockets. I have
I'm trying to implement TCP hole punching with windows socket using mingw toolchain. I
i'm trying use facebook API to upload photo in my fan page. I downloaded
I'm trying to create a chat server using sockets in Perl. However, when I
I'm trying to use LISTSERV's API in PHP. L-Soft calls this TCPGUI, and essentially,

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.