Network Communication API Editor's Draft

Fri, 23 Nov 2007 11:42:56 GMT
by pdp

To enable Web applications to communicate using TCP this specification introduces the TCPSocket interface and a corresponding optional security model.

var con = null;

try { 
    con = new TCPSocket("www.[example](https://chatbotkit.com/examples).com, "12345");
} catch (ex) { 
    if ("SECURITY_ERR" == ex.message) { 
        alert("unable to connect");
    }
}

con.addEventListener("socketdata", function(ev) {
    if ("pong" == ev.data) {
        alert("Success");
    }
    else {
        alert("Failure");
    }
}

con.write("ping");
con.flush();

The TCPSocket interface enables a TCP connection from the client to the server from which the script was downloaded and executed from. Instances of this object can be made using a constructor on the Window object. W3C

Cool stuff!

Archived Comments

Wladimir PalantWladimir Palant
Great, the last thing the world needs is yet another way of sending raw TCP data. On the other hand, Java and Flash do this already...
MattMatt
Is this API downloadable yet? I also noticed that you used a closure in your function declaration of the event handler so it is definitely not Java. Is it JavaScript perchance?
pdppdp
well TCPSocket is already implemented into Firefox but it is not part of the DOM. So, this draft suggests that the object it should be part of it and in a year or two, that might be the case.