[go-nuts] Re: Print something while read message from server with websocket

2020-03-27 Thread 洪嘉鴻
I'm sorry that I didn't remind that my Client code does not compile.
I've tried your example  with 
SetReadDeadline 
().
It seems like what I want to do.

Thank you very much!
  Max

Jake Montgomery於 2020年3月27日星期五 UTC+8上午1時12分07秒寫道:
>
> Your Client  code does not 
> compile. As a courtesy to those trying to help, it is always good to test 
> your code before posting it. A working example, without your "busy" 
> messages would be something like: https://play.golang.org/p/cvgwd8GDobc . 
> The Read() method documentation 
>  says "Read 
> implements the io.Reader interface." So I suggest you *carefully *read 
> the io.Reader documentation , because 
> it requires very specific handling to be done correctly. 
>
> Also, I did note that golang.org/x/net/websocket documentation 
>  states that: "This package 
> currently lacks some features found in alternative and more actively 
> maintained WebSocket packages." So you may want to consider using one of 
> those. 
>
> I have not actually used golang.org/x/net 
> /websocket myself, but there is a 
> SetReadDeadline 
> () 
> function. Because I have not used the package before, there may be some 
> hidden pitfalls that I am missing, but this code seems to do what you want, 
> using SetReadDeadline 
> (): 
> https://play.golang.org/p/ISUR7c_Mtqb
>
> Good luck
>
> On Wednesday, March 25, 2020 at 8:56:57 PM UTC-4, 洪嘉鴻 wrote:
>>
>> I'm sorry.
>> The followings are the complete codes of server and client:
>> Server 
>> Client 
>>
>> Thank you very much!
>>   Max
>>
>> Jake Montgomery於 2020年3月25日星期三 UTC+8下午9時28分37秒寫道:
>>>
>>> You do not provide enough information to give a really good answer. 
>>> There are a number of ways to achieve this, but they depend on the details. 
>>> A more complete example would help. 
>>>
>>> What is the type of `ws`? If it is something on which you can set a read 
>>> timeout, then one way would be to set a timeout, and loop.
>>>
>>> On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:

 Hello everyone:
   The version of the golang which I am using is 1.12.9 with Win10.
   I want to print something while the client is waiting for server.
   The following are the partial code of server and client.

   Server:
   time.Sleep(time.Second * 100)
   ws.Write([]byte("Hello!"))
   
   Client:
   while(!ws.Read(msg)){
   fmt.Println("Please wait because server is busy.")  
   }

   Can anyone suggest how to fix the code?

   Any help is appreciated.
   Thank you very much!
   Max

>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ac4c3a2d-9305-4775-bc84-a91c8661bc38%40googlegroups.com.


[go-nuts] Re: Print something while read message from server with websocket

2020-03-26 Thread 洪嘉鴻
Thanks for your replying.
I'm sorry that I didn't remind that my Client code does not compile.
I've tried your example  with 
SetReadDeadline 
().
It seems like what I want to do.
However, I want to edit "spinner" message instead of "busy" message, as the 
followings:
Server  code is the same.
Here is the new Client  code.

I only want to show "Wait..." message before reading "Hello!" message.
Nevertheless, the results would be a little mess.
I have no idea what's wrong with the codes. 

Thank you very much!
  Max

Jake Montgomery於 2020年3月27日星期五 UTC+8上午1時12分07秒寫道:
>
> Your Client  code does not 
> compile. As a courtesy to those trying to help, it is always good to test 
> your code before posting it. A working example, without your "busy" 
> messages would be something like: https://play.golang.org/p/cvgwd8GDobc . 
> The Read() method documentation 
>  says "Read 
> implements the io.Reader interface." So I suggest you *carefully *read 
> the io.Reader documentation , because 
> it requires very specific handling to be done correctly. 
>
> Also, I did note that golang.org/x/net/websocket documentation 
>  states that: "This package 
> currently lacks some features found in alternative and more actively 
> maintained WebSocket packages." So you may want to consider using one of 
> those. 
>
> I have not actually used golang.org/x/net 
> /websocket myself, but there is a 
> SetReadDeadline 
> () 
> function. Because I have not used the package before, there may be some 
> hidden pitfalls that I am missing, but this code seems to do what you want, 
> using SetReadDeadline 
> (): 
> https://play.golang.org/p/ISUR7c_Mtqb
>
> Good luck
>
> On Wednesday, March 25, 2020 at 8:56:57 PM UTC-4, 洪嘉鴻 wrote:
>>
>> I'm sorry.
>> The followings are the complete codes of server and client:
>> Server 
>> Client 
>>
>> Thank you very much!
>>   Max
>>
>> Jake Montgomery於 2020年3月25日星期三 UTC+8下午9時28分37秒寫道:
>>>
>>> You do not provide enough information to give a really good answer. 
>>> There are a number of ways to achieve this, but they depend on the details. 
>>> A more complete example would help. 
>>>
>>> What is the type of `ws`? If it is something on which you can set a read 
>>> timeout, then one way would be to set a timeout, and loop.
>>>
>>> On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:

 Hello everyone:
   The version of the golang which I am using is 1.12.9 with Win10.
   I want to print something while the client is waiting for server.
   The following are the partial code of server and client.

   Server:
   time.Sleep(time.Second * 100)
   ws.Write([]byte("Hello!"))
   
   Client:
   while(!ws.Read(msg)){
   fmt.Println("Please wait because server is busy.")  
   }

   Can anyone suggest how to fix the code?

   Any help is appreciated.
   Thank you very much!
   Max

>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d3652a2e-13e0-4374-a098-e0c092f77b62%40googlegroups.com.


[go-nuts] Re: Print something while read message from server with websocket

2020-03-26 Thread 洪嘉鴻
I'm sorry that I didn't remind that my Client code does not compile.
I've tried your example  with 
SetReadDeadline 
().
It seems like what I want to do.

Thank you very much!
  Max

Jake Montgomery於 2020年3月27日星期五 UTC+8上午1時12分07秒寫道:
>
> Your Client  code does not 
> compile. As a courtesy to those trying to help, it is always good to test 
> your code before posting it. A working example, without your "busy" 
> messages would be something like: https://play.golang.org/p/cvgwd8GDobc . 
> The Read() method documentation 
>  says "Read 
> implements the io.Reader interface." So I suggest you *carefully *read 
> the io.Reader documentation , because 
> it requires very specific handling to be done correctly. 
>
> Also, I did note that golang.org/x/net/websocket documentation 
>  states that: "This package 
> currently lacks some features found in alternative and more actively 
> maintained WebSocket packages." So you may want to consider using one of 
> those. 
>
> I have not actually used golang.org/x/net 
> /websocket myself, but there is a 
> SetReadDeadline 
> () 
> function. Because I have not used the package before, there may be some 
> hidden pitfalls that I am missing, but this code seems to do what you want, 
> using SetReadDeadline 
> (): 
> https://play.golang.org/p/ISUR7c_Mtqb
>
> Good luck
>
> On Wednesday, March 25, 2020 at 8:56:57 PM UTC-4, 洪嘉鴻 wrote:
>>
>> I'm sorry.
>> The followings are the complete codes of server and client:
>> Server 
>> Client 
>>
>> Thank you very much!
>>   Max
>>
>> Jake Montgomery於 2020年3月25日星期三 UTC+8下午9時28分37秒寫道:
>>>
>>> You do not provide enough information to give a really good answer. 
>>> There are a number of ways to achieve this, but they depend on the details. 
>>> A more complete example would help. 
>>>
>>> What is the type of `ws`? If it is something on which you can set a read 
>>> timeout, then one way would be to set a timeout, and loop.
>>>
>>> On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:

 Hello everyone:
   The version of the golang which I am using is 1.12.9 with Win10.
   I want to print something while the client is waiting for server.
   The following are the partial code of server and client.

   Server:
   time.Sleep(time.Second * 100)
   ws.Write([]byte("Hello!"))
   
   Client:
   while(!ws.Read(msg)){
   fmt.Println("Please wait because server is busy.")  
   }

   Can anyone suggest how to fix the code?

   Any help is appreciated.
   Thank you very much!
   Max

>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c283ad5f-52e9-4666-8bd4-c205300ed21f%40googlegroups.com.


[go-nuts] Re: Print something while read message from server with websocket

2020-03-26 Thread Jake Montgomery
Your Client  code does not compile. 
As a courtesy to those trying to help, it is always good to test your code 
before posting it. A working example, without your "busy" messages would be 
something like: https://play.golang.org/p/cvgwd8GDobc . The Read() method 
documentation  says 
"Read implements the io.Reader interface." So I suggest you *carefully *read 
the io.Reader documentation , because it 
requires very specific handling to be done correctly. 

Also, I did note that golang.org/x/net/websocket documentation 
 states that: "This package 
currently lacks some features found in alternative and more actively 
maintained WebSocket packages." So you may want to consider using one of 
those. 

I have not actually used golang.org/x/net 
/websocket myself, but there is a 
SetReadDeadline 
() 
function. Because I have not used the package before, there may be some 
hidden pitfalls that I am missing, but this code seems to do what you want, 
using SetReadDeadline 
(): 
https://play.golang.org/p/ISUR7c_Mtqb

Good luck

On Wednesday, March 25, 2020 at 8:56:57 PM UTC-4, 洪嘉鴻 wrote:
>
> I'm sorry.
> The followings are the complete codes of server and client:
> Server 
> Client 
>
> Thank you very much!
>   Max
>
> Jake Montgomery於 2020年3月25日星期三 UTC+8下午9時28分37秒寫道:
>>
>> You do not provide enough information to give a really good answer. There 
>> are a number of ways to achieve this, but they depend on the details. A 
>> more complete example would help. 
>>
>> What is the type of `ws`? If it is something on which you can set a read 
>> timeout, then one way would be to set a timeout, and loop.
>>
>> On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:
>>>
>>> Hello everyone:
>>>   The version of the golang which I am using is 1.12.9 with Win10.
>>>   I want to print something while the client is waiting for server.
>>>   The following are the partial code of server and client.
>>>
>>>   Server:
>>>   time.Sleep(time.Second * 100)
>>>   ws.Write([]byte("Hello!"))
>>>   
>>>   Client:
>>>   while(!ws.Read(msg)){
>>>   fmt.Println("Please wait because server is busy.")  
>>>   }
>>>
>>>   Can anyone suggest how to fix the code?
>>>
>>>   Any help is appreciated.
>>>   Thank you very much!
>>>   Max
>>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c1e09631-eea3-40e2-bb5a-246906e17508%40googlegroups.com.


[go-nuts] Re: Print something while read message from server with websocket

2020-03-25 Thread 洪嘉鴻
I'm sorry.
The followings are the complete codes of server and client:
Server 
Client 

Thank you very much!
  Max

Jake Montgomery於 2020年3月25日星期三 UTC+8下午9時28分37秒寫道:
>
> You do not provide enough information to give a really good answer. There 
> are a number of ways to achieve this, but they depend on the details. A 
> more complete example would help. 
>
> What is the type of `ws`? If it is something on which you can set a read 
> timeout, then one way would be to set a timeout, and loop.
>
> On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:
>>
>> Hello everyone:
>>   The version of the golang which I am using is 1.12.9 with Win10.
>>   I want to print something while the client is waiting for server.
>>   The following are the partial code of server and client.
>>
>>   Server:
>>   time.Sleep(time.Second * 100)
>>   ws.Write([]byte("Hello!"))
>>   
>>   Client:
>>   while(!ws.Read(msg)){
>>   fmt.Println("Please wait because server is busy.")  
>>   }
>>
>>   Can anyone suggest how to fix the code?
>>
>>   Any help is appreciated.
>>   Thank you very much!
>>   Max
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d83ed07c-b452-4e9c-98a7-d1853299db5e%40googlegroups.com.


[go-nuts] Re: Print something while read message from server with websocket

2020-03-25 Thread Jake Montgomery
You do not provide enough information to give a really good answer. There 
are a number of ways to achieve this, but they depend on the details. A 
more complete example would help. 

What is the type of `ws`? If it is something on which you can set a read 
timeout, then one way would be to set a timeout, and loop.

On Wednesday, March 25, 2020 at 4:10:19 AM UTC-4, 洪嘉鴻 wrote:
>
> Hello everyone:
>   The version of the golang which I am using is 1.12.9 with Win10.
>   I want to print something while the client is waiting for server.
>   The following are the partial code of server and client.
>
>   Server:
>   time.Sleep(time.Second * 100)
>   ws.Write([]byte("Hello!"))
>   
>   Client:
>   while(!ws.Read(msg)){
>   fmt.Println("Please wait because server is busy.")  
>   }
>
>   Can anyone suggest how to fix the code?
>
>   Any help is appreciated.
>   Thank you very much!
>   Max
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d267f032-09e3-4224-90d1-b4939ebca69a%40googlegroups.com.