Supporting TCP listening/server socket in chrome.experimental.socket API

1,546 views
Skip to first unread message

ningxin hu

unread,
May 29, 2012, 9:08:19 PM5/29/12
to Chromium-extensions
Currently chrome.experimental.socket API doesn't support TCP
listening/
server socket. With TCP listening/server socket, extensions could
expose services such as for remote control, system integration etc.,

So I propose to add TCP listening/server socket support with some new
APIs:
[nodoc] namespace experimental.socket {
...
dictionary AcceptInfo {
// The id of the newly connected socket.
long socketId;

// Peer address of the connection.
DOMString address;
long port;
};

callback AcceptCallback = void (AcceptInfo acceptInfo);
...
interface Functions {
...
// Listens for connections on a TCP socket. The socket should be
// bound to a local endpoint before listening.
// |socketId| : The socketId.
// |backlog| : The maximum length of the queue of the pending
// connections. The default value is 5.
static void listen(long socketId,
optional long backlog);

// Accepts a connection on a listening socket.
// |socketId| : The socketId of the listening socket.
// |callback| : called when accept attempt is completed.
static void accept(long socketId,
AcceptCallback callback);
};

};

An example of APIs usage is:
//-----------------------------------------------------------------------------------------------------------------
var listening_socket_id = -1;
var server_socket_id = -1;

function dataReceived(info) {
if (info.resultCode > 0) {
chrome.experimental.socket.write(server_socket_id,
info.data,
function (info)
{ });
}
};

function connectionAccepted(info) {
if (info.socketId > 0) {
server_socket_id = info.socketId;
chrome.experimental.socket.read(server_socket_id, dataReceived);
}
};

function socketBound(result) {
if (result == 0) {
chrome.experimental.socket.listen(listening_socket_id);
chrome.experimental.socket.accept(listening_socket_id,

connectionAccepted);
}

};

function socketCreated(info) {
listening_socket_id = info.socketId;
chrome.experimental.socket.bind(listening_socket_id, "127.0.0.1",
8800, socketBound);
};

chrome.experimental.socket.create("tcp", socketCreated);
//----------------------------------------------------------------------------------------------------------------------

Thoughts? Concerns? If folks like this proposal, I will upload a CL
for review.

BTW, I cannot find the existing socket proposal
page under http://dev.chromium.org/developers/design-documents/extensions/.
Is it hosted in another place?

Thanks,
-ningxin

ryan

unread,
Jun 4, 2012, 6:32:26 PM6/4/12
to Chromium-extensions
Yeah, someone at Google forgot to do a few things. This API isn't
listed under http://code.google.com/chrome/extensions/experimental.html#overview
but googling for it shows this page:

http://code.google.com/chrome/extensions/experimental.socket.html

I would have never known about it unless I accidentally saw this
post.
> page underhttp://dev.chromium.org/developers/design-documents/extensions/.

Mike Tsao

unread,
Jun 5, 2012, 12:18:04 PM6/5/12
to ryan, Chromium-extensions
See http://code.google.com/searchframe#OAMlx_jo-ck/src/chrome/common/extensions/api/experimental_socket.idl&exact_package=chromium&q=experimental%20socket%20idl&type=cs&l=7.
The IDL marks these APIs with the "nodoc" attribute because they're
very early in the experimental development process, and it would be
misleading to potential developers to begin documenting them on the
website.

Ryan, you are correct that "someone [on the Chromium team] forgot to
do a few things." Specifically, the document generator was briefly
failing to completely respect the nodoc attribute, causing a very
outdated version of the page you've cited to be rolled out to the
website as an orphan. That page should not exist. The IDL, however,
will remain authoritative.
> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>

PhistucK

unread,
Jun 5, 2012, 1:10:18 PM6/5/12
to Mike Tsao, ryan, Chromium-extensions
Note that I saw a change list that is going to take it out of experimental.

PhistucK
Reply all
Reply to author
Forward
0 new messages