FAQ
hi,

In the func main(),I have below line...

*http.HandleFunc("/", MainServer**)*

In the MainServer function I have html code and return m as below








*MainServer(){in html: <form id="msgform" ..> <input type="file"
name="fileform"> .. in javascript: m =
document.getElementById('msgform').fileform.files[0]; ws.send(m);}*
To access this file data I knew that I have to use following line...



*var buf []byte err := websocket.Message.Receive(ws, &buf) if err { .. }*


If I access this data in wsserver function,how can I write this output to
the webpage?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • kate Fernando at Jan 21, 2014 at 12:43 pm
    I used the code in follow url.

    https://github.com/ukai/go-websocket-sample/blob/master/websocket_echo_sample.go

    when the user submit the value through browser, I need to output that value
    to the webpage.how can I achieve that?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Caleb Doxsey at Jan 21, 2014 at 1:35 pm
    WebSockets are bidirectional; you can both read from them and send to them.
    In Javascript you send and receive this way:

    var ws = new WebSocket("URL")
    // send
    ws.send("text")
    ws.onmessage = function(evt) {
         // receive
         console.log(evt.data)
    }


    In the echo example you can see that he both sends and receives like this:

    func sendRecvServer(ws *websocket.Conn) {
             fmt.Printf("sendRecvServer %#v\n", ws)
             for {
                     var buf string
                     // Receive receives a text message from client, since buf
    is string.
                     err := websocket.Message.Receive(ws, &buf)
                     if err != nil {
                             fmt.Println(err)
                             break
                     }
                     fmt.Printf("recv:%q\n", buf)
                     // Send sends a text message to client, since buf is string.
                     err = websocket.Message.Send(ws, buf)
                     if err != nil {
                             fmt.Println(err)
                             break
                     }
                     fmt.Printf("send:%q\n", buf)
             }
             fmt.Println("sendRecvServer finished")
    }


    So if you hit the /sendRecvText url it should echo back anything you send
    it. To make that show up on the page you just need to do something like:
    (in your onmessage handler)

    document.getElementById("someid").textContent += evt.data;


    If that doesn't make sense you may want to read up on Javascript and how it
    interacts with the DOM. (You might find a library like jQuery easier to use)

    On Tue, Jan 21, 2014 at 5:43 AM, kate Fernando wrote:


    I used the code in follow url.


    https://github.com/ukai/go-websocket-sample/blob/master/websocket_echo_sample.go

    when the user submit the value through browser, I need to output that
    value to the webpage.how can I achieve that?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • kate Fernando at Jan 21, 2014 at 2:48 pm
    thanks.....

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 21, '14 at 12:15p
activeJan 21, '14 at 2:48p
posts4
users2
websitegolang.org

2 users in discussion

kate Fernando: 3 posts Caleb Doxsey: 1 post

People

Translate

site design / logo © 2021 Grokbase