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