Skip to content

Instantly share code, notes, and snippets.

@fkei
Created March 31, 2011 09:01
Show Gist options
  • Save fkei/896064 to your computer and use it in GitHub Desktop.
Save fkei/896064 to your computer and use it in GitHub Desktop.
Changes in 1.4.01 from 1.4.02, multibyte character "Connection.prototype.write (data)" has stopped working.
--- lib/ws/connection.js.orig 2011-03-31 16:43:40.000000000 +0900
+++ lib/ws/connection.js 2011-03-31 16:45:33.000000000 +0900
@@ -182,10 +182,10 @@
/*-----------------------------------------------
Various utility style functions:
-----------------------------------------------*/
-function write(connection, data) {
+function write(connection, data, encoding) {
debug(connection.id, 'write: ', (new Buffer(data)).inspect());
if (connection._socket.writable) {
- return connection._socket.write(data, 'binary');
+ return connection._socket.write(data, encoding);
}
return false;
}
@@ -282,7 +282,15 @@
Connection.prototype.write = function(data) {
if (this._state === 4) {
- return write(this, '\u0000' + data + '\uffff');
+ if(
+ write(this, "\u0000", "binary") &&
+ write(this, data, "utf8") &&
+ write(this, "\uffff", "binary")
+ ) {
+ return true;
+ } else {
+ debug(this.id, "\033[31mERROR: write: "+data);
+ }
} else {
debug(this.id, '\033[31mCould not send.');
}
@ThisIsMissEm
Copy link

I have also made inquiries with peter griess who gave the original code for writing this data out, in the three sequential writes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment