不管是什么文本還是二進制數(shù)據(jù),都是在onMessage里接收,沒有區(qū)別。
如果是websocket協(xié)議,發(fā)送二進制數(shù)據(jù)需要設置一個標記位,參考手冊http://doc.workerman.net/315305
已經發(fā)送成功了,我直接在onMessage里面接收的,也成功了,但是他有大小設置,我設置了$connection->maxSendBufferSize但是還是報錯,這個問題遇到過沒有???
<!doctype html>
<html lang="en">
<head>
<title>Document</title>
<input type='file' name='img' onchange='showlist(this.files)'/>
</head>
<body>
<script>
function showlist(files)
{
var reader = new FileReader();
var result;
var file=files;
reader.onload = function()
{
result = this.result;
}
reader.readAsBinaryString(file);
var ws = new WebSocket('ws://192.168.2.183:1234');
ws.onopen = function()
{
var uid = 'uid2';
ws.send(file);
};
ws.onmessage = function(e)
{
console.log(e.data);
};
}
</script>
<script>
</script>
</body>
</html>