{"action":"closed","issue":{"url":"https://api.github.com/repos/totaljs/framework/issues/352","labels_url":"https://api.github.com/repos/totaljs/framework/issues/352/labels{/name}","comments_url":"https://api.github.com/repos/totaljs/framework/issues/352/comments","events_url":"https://api.github.com/repos/totaljs/framework/issues/352/events","html_url":"https://github.com/totaljs/framework/issues/352","id":126152045,"number":352,"title":"Server can decode buffer from Client, but Client can't decode buffer from Server.","user":{"login":"liaosankai","id":82476,"avatar_url":"https://avatars.githubusercontent.com/u/82476?v=3","gravatar_id":"","url":"https://api.github.com/users/liaosankai","html_url":"https://github.com/liaosankai","followers_url":"https://api.github.com/users/liaosankai/followers","following_url":"https://api.github.com/users/liaosankai/following{/other_user}","gists_url":"https://api.github.com/users/liaosankai/gists{/gist_id}","starred_url":"https://api.github.com/users/liaosankai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liaosankai/subscriptions","organizations_url":"https://api.github.com/users/liaosankai/orgs","repos_url":"https://api.github.com/users/liaosankai/repos","events_url":"https://api.github.com/users/liaosankai/events{/privacy}","received_events_url":"https://api.github.com/users/liaosankai/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/totaljs/framework/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/totaljs/framework/labels/websocket","name":"websocket","color":"006b75"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-12T10:51:06Z","updated_at":"2016-01-12T13:02:35Z","closed_at":"2016-01-12T13:02:35Z","body":"Hi, @petersirka \r\n\r\nI forgot to try decode buffer from server in client. I can decode protobuf from client in server,but can't decode protobuf from server in client. I try encode/decode simple binary in server/client and got the same problem.\r\n\r\n### Server\r\nfile in `controllers/default.js`\r\n\r\n\texports.install = function() {\r\n\t    F.route('/', view_index);\r\n\t    F.websocket('/binary', socket_binary, ['binary'], [], ['*']);\r\n\t};\r\n\r\n\tfunction view_index() {\r\n\t    var self = this;\r\n\t    self.view('index');\r\n\t}\r\n\r\n\tfunction socket_binary() {\r\n\t    var controller = this;\r\n\t    var ab2str = function(buf) {\r\n\t        return String.fromCharCode.apply(null, new Uint16Array(buf));\r\n\t    }\r\n\t    var str2ab = function(str) {\r\n\t        var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\r\n\t        var bufView = new Uint16Array(buf);\r\n\t        for (var i = 0, strLen = str.length; i < strLen; i++) {\r\n\t            bufView[i] = str.charCodeAt(i);\r\n\t        }\r\n\t        return buf;\r\n\t    }\r\n\t    controller.on('open', function(client) {\r\n\t        console.log('Connect / Online:', controller.online);\r\n\t    });\r\n\t    controller.on('close', function(client) {\r\n\t        console.log('Disonnect / Online:', controller.online);\r\n\t    });\r\n\t    controller.on('message', function(client, arraybuffer) {\r\n\t        var msg = ab2str(arraybuffer);\r\n\t        console.log('--- BINARY ---');\r\n\t        console.log(msg); // <- It's working.\r\n\r\n\t        // send to client\r\n\t        var buffer = str2ab(msg);\r\n\t        controller.send(buffer);\r\n\t    });\r\n\t}\r\n\r\n\r\n### Client\r\nfile in `views/index.html`\r\n\r\n\t<button id=\"test-binary\">\r\n\t    ws://127.0.0.1:8000/binary\r\n\t</button>\r\n\t<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js\"></script>\r\n\t<script>\r\n\t$(document).ready(function() {\r\n\r\n\t    var socket = null;\r\n\r\n\t    $('#test-binary').on('click', function() {\r\n\t        var ab2str = function(buf) {\r\n\t            return String.fromCharCode.apply(null, new Uint16Array(buf));\r\n\t        }\r\n\t        var str2ab = function(str) {\r\n\t            var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\r\n\t            var bufView = new Uint16Array(buf);\r\n\t            for (var i = 0, strLen = str.length; i < strLen; i++) {\r\n\t                bufView[i] = str.charCodeAt(i);\r\n\t            }\r\n\t            return buf;\r\n\t        }\r\n\t        socket = new WebSocket('ws://127.0.0.1:8000/binary');\r\n\t        socket.binaryType = 'arraybuffer';\r\n\t        socket.onopen = function() {\r\n\t            console.log('connecting...');\r\n\t            if (socket.readyState === WebSocket.OPEN) {\r\n\t                console.log('connected');\r\n\t                console.log('Send test message');\r\n\t                var buffer = str2ab('TEST ARRAY BUFFER');\r\n\t                socket.send(buffer);\r\n\t            } else {\r\n\t                console.log('disconnected');\r\n\t            }\r\n\t        };\r\n\t        socket.onmessage = function(evt) {\r\n\t            var data = ab2str(evt.data);\r\n\t            console.log('msg from server:', data); // <- It's not working.\r\n\t        }\r\n\t    });\r\n\t});\r\n\t</script>\r\n\r\n### ENV\r\n+ node 5.1.1\r\n+ windows10 MINGW64 shell\r\n+ total.js@1.9.6-16"}}