You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry to bother you. But i have found the bug.
It is in neffos.js.
I'm using protobuf with neffos.js. The data that protobuf make counld contain ;. So that my message will be drop in neffos.js in here.
varisArrayBuffer=datainstanceofArrayBuffer;vardts;console.log(isArrayBuffer)if(isArrayBuffer){vararr=newUint8Array(data);varsepCount=1;varlastSepIndex=0;for(vari=0;i<arr.length;i++){if(arr[i]==messageSeparatorCharCode){// sep char.sepCount++;lastSepIndex=i;}}// Drop here!!!!!!!!!!!!if(sepCount!=validMessageSepCount){msg.isInvalid=true;console.log("return at validMessageSepCount")returnmsg;}dts=splitN(textDecoder.decode(arr.slice(0,lastSepIndex)),messageSeparator,validMessageSepCount-2);dts.push(data.slice(lastSepIndex+1,data.length));msg.SetBinary=true;}else{dts=splitN(data,messageSeparator,validMessageSepCount-1);}
I thank it is a bug. Cannot just split message by ;.
Here is the reproducible code.
Server
package main
import (
"github.com/kataras/iris""fmt""github.com/kataras/iris/websocket""github.com/kataras/neffos""time"
)
// 全局变量varpage=struct {
Titlestring
}{"Collector"}
funcmain(){
app:=iris.New()
ws_server:=startWebSocketServer(app)
gopub_thread(ws_server)
app.RegisterView(iris.HTML("./static", ".html"))
app.Get("/" ,func(ctx iris.Context){
ctx.ViewData("Page", page)
ctx.View("index.html")
})
app.HandleDir("/", "./static")
app.Run(iris.Addr(":5000"), iris.WithoutPathCorrection)
}
varserverEvents= websocket.Namespaces{
"default": websocket.Events{
websocket.OnNamespaceConnected: func(nsConn*websocket.NSConn, msg websocket.Message) error {
// with `websocket.GetContext` you can retrieve the Iris' `Context`.ctx:=websocket.GetContext(nsConn.Conn)
fmt.Printf("[%s] connected to namespace [%s] with IP [%s]\n",
nsConn, msg.Namespace,
ctx.RemoteAddr())
returnnil
},
websocket.OnNamespaceDisconnect: func(nsConn*websocket.NSConn, msg websocket.Message) error {
fmt.Printf("[%s] disconnected from namespace [%s]\n", nsConn, msg.Namespace)
returnnil
},
"stream": func(nsConn*websocket.NSConn, msg websocket.Message) error {
// room.String() returns -> NSConn.String() returns -> Conn.String() returns -> Conn.ID()fmt.Printf("[%s] sent: %s", nsConn, string(msg.Body))
// Write message back to the client message owner with:// nsConn.Emit("chat", msg)// Write message to all except this client with:nsConn.Conn.Server().Broadcast(nsConn, msg)
returnnil
},
},
}
funcstartWebSocketServer(app*iris.Application) *neffos.Server{
server:=websocket.New(websocket.DefaultGorillaUpgrader, serverEvents)
server.OnConnect=func(c*websocket.Conn) error {
fmt.Printf("[%s] connected to the server.\n", c)
returnnil
}
server.OnDisconnect=func(c*websocket.Conn){
fmt.Printf("[%s] disconnected from the server.", c)
}
fmt.Printf("Listening on: %d\nPress CTRL/CMD+C to interrupt.\n", 5000)
idGen:=func(ctx iris.Context) string {
ifusername:=ctx.GetHeader("X-Username"); username!="" {
returnusername
}
returnwebsocket.DefaultIDGenerator(ctx)
}
app.Get("/stream", websocket.Handler(server, idGen))
returnserver
}
funcpub_thread(serve*neffos.Server){
png:= [...] byte{';',';',';',';',';'}
slice:=png[:]
for{
serve.Broadcast(nil, neffos.Message{SetBinary: true, Body:slice, Namespace: "default"})
time.Sleep(1*time.Second)
}
}
Client
<html><button> useless button</button><scriptsrc="https://cdn.jsdelivr.net/npm/neffos.js@latest/dist/neffos.js"></script><script>
var scheme = document.location.protocol == "https:" ? "wss" : "ws";
var port = document.location.port ? ":" + document.location.port : "";
var wsURL = scheme + "://" + document.location.hostname + port + "/stream";
function handleError(reason) {console.log(reason);}
function handleNamespaceConnectedConn(nsConn) {}
// const username = window.prompt("Your username?");
async function runExample() {// You can omit the "default" and simply define only Events, the namespace will be an empty string"",// however if you decide to make any changes on this example make sure the changes are reflecting inside the ../server.go file as well.try{
const conn=awaitneffos.dial(wsURL,{default: {// "default" namespace._OnNamespaceConnected: function(nsConn,msg){handleNamespaceConnectedConn(nsConn)},_OnNamespaceDisconnect: function(nsConn,msg){},stream: function(nsConn,msg){// "stream" event.console.log(msg.Body);console.log(msg)}}},{headers: {"X-Username": "",}});// You can either wait to conenct or just conn.connect("connect")// and put the `handleNamespaceConnectedConn` inside `_OnNamespaceConnected` callback instead.// const nsConn = await conn.connect("default");// nsConn.emit(...); handleNamespaceConnectedConn(nsConn);conn.connect("default");}catch(err){handleError(err);}}
runExample()
</script></html>
The text was updated successfully, but these errors were encountered:
Does the protobuf example: https://github.com/kataras/neffos/blob/master/_examples/protobuf/main.go fits your needs? I see your point but messages containing ; are escaped when sending from javascript client (see neffos.js). So, could you please give me a reproducible example (preferable upload to a github repository) so I can run it and resolve in order to fix any issue?
Hi @kataras , run the protobuf example. I have got some problems.
When i send message from ./protobuf client to server. The javascript client got this problem:
If i send message fron javascript client, the other javascript client will receive the message, but the ./protobuf client got nothing. And the ./protobuf server will print remote error: proto: can't skip unknown wire type 4. You can see it in the screenshot above.
What i want is : send binary data from 'go side' to 'javascript side'.
Sorry to bother you. But i have found the bug.
It is in
neffos.js
.I'm using
protobuf
withneffos.js
. Thedata that protobuf make
counld contain;
. So that my message will be drop inneffos.js
in here.I thank it is a bug. Cannot just split message by
;
.Here is the reproducible code.
Server
Client
The text was updated successfully, but these errors were encountered: