help with integrating websockets and protobuf

83 views
Skip to first unread message

Jon Norberg

unread,
Jul 22, 2016, 11:02:40 AM7/22/16
to julia-users
Dear julia community.

I can't figure out whats wrong here. I have a web socket implementation that works just fine without using protobuf on the julsa/websocket side (in fact, the html-client does send a protobuf array which just gets sent back without unpacking and packing on the julia web socket side, i.e. echo server.

the relevant lines in the web socket server are:

msg = read(client) # This receives messages
write(client,msg) # This sends it back

I can then unpack it on the html-client side again just fine.

I have defined a protobuf type as

type com
id::Array{Int32,1}
val::Array{Float32,1}
com(; kwargs...) = (o=new(); fillunset(o); isempty(kwargs) || ProtoBuf._protobuild(o, kwargs); o)
end #type com
hash(v::com) = ProtoBuf.protohash(v)
isequal(v1::com, v2::com) = ProtoBuf.protoisequal(v1, v2)
==(v1::com, v2::com) = ProtoBuf.protoeq(v1, v2)

and the following works as it should:

iob = PipeBuffer();
writeproto(iob,com(id=[1],val=[0.2]))
msg = readproto(iob,com())
println(msg)

But when I change the relevant lines in the web socket code on the server side to:

msg = readproto(client.socket,com())
writeproto(client.socket,com(id=[1],val=[0.2]))

it does not work.

I did figure out that client is a composite type and that client.socket is of type TCPSocket which I assume is the right variable to pass to the protobuf functions.

Can anyone spot what I am missing?

the protofile is:

message com {
repeated int32 id = 1;
repeated float val =2;
}

Jon Norberg

unread,
Jul 22, 2016, 11:16:49 AM7/22/16
to julia-users
just to check that there is no problem in the formats, the following does send a ljulia-protobuf formatted message to the html-client but somewhat indirectly....

msg = read(client)
iob = PipeBuffer();
write(iob,msg)
test = readproto(iob,com())
println("got MESSAGE: $test.id") #i.e. works!


writeproto(iob,com(id=[1],val=[0.2]))

msg=read(iob)
write(client,msg) #the new value turns up at the client, so no issues with the formatting, just to get the web socket to talk via readproto and writeproto

Jon Norberg

unread,
Jul 25, 2016, 7:03:50 AM7/25/16
to julia-users
Anyone have any experiences with protobuf/web Sockets?

Reply all
Reply to author
Forward
0 new messages