[go-nuts] Re: Surprising benchmark result

2021-07-07 Thread peterGo
Revised results using the same input data for each iteration without a copy 
just a Filter function.

i7-7500U
name   time/op
Filter3-4  2.29µs ± 0%
Filter4-4  1.51µs ± 0%

i5-8250U
name   time/op
Filter3-8  2.30µs ± 0%
Filter4-8  1.53µs ± 0%

Peter

On Wednesday, July 7, 2021 at 11:25:11 AM UTC-4 tapi...@gmail.com wrote:

> It is found that the test file is not written correctly.
> The filtered data should be reset in each loop.
> The corrected one: https://play.golang.org/p/yJMweZLIXAz 
> 
>
> ;D
>
> On Monday, June 7, 2021 at 10:57:19 AM UTC-4 tapi...@gmail.com wrote:
>
>>
>> The code: https://play.golang.org/p/DxUj6kBqf8k
>>
>> The Filter4 function has one more assignment statement than Filter3.
>> But the benchmark result shows Filter4 is faster than Filter3.
>>
>> The result:
>>
>> cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
>> BenchmarkFilter3-43575656   980.2 ns/op   0 
>> B/op   0 allocs/op
>> BenchmarkFilter4-43956533   916.8 ns/op   0 
>> B/op   0 allocs/op
>>
>>
>>

-- 
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/da1cc2bd-a54d-402a-ac0d-9f7300dbd207n%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread peterGo
On Wednesday, July 7, 2021 at 8:01:54 PM UTC-4 tapi...@gmail.com wrote:

> Peter's solution exhausted my memory and hang my whole computer, and I 
> have to restart it.
>

Adjust the number of iterations (b.N), to accomodate your limited memory, 
For example, for 8GB use 100,000,

   $ go test filter_test.go -bench=Filter -benchmem -benchtime=10x

Peter

 
>
>>
>> On Wednesday, July 7, 2021 at 11:29:30 AM UTC-4 tapi...@gmail.com wrote:
>>
>>> This doesn't work:
>>>
>>> func BenchmarkFilter3(b *testing.B) {
>>> data := buildOrginalData()
>>> data2 := make([]int, len(data))
>>> b.ResetTimer()
>>> for i := 0; i < b.N; i++ {
>>> b.StopTimer()
>>> copy(data2, data)
>>> b.StartTimer()
>>> _ = Filter3(data2)
>>> }
>>> }
>>>
>>> On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:
>>>

 For example, I don't want the time consumed for "copy(data2, data)" 
 being counted.
 How to achieve this?

 func BenchmarkFilter3(b *testing.B) {
 data := buildOrginalData()
 data2 := make([]int, len(data))
 b.ResetTimer()
 for i := 0; i < b.N; i++ {
 copy(data2, data)
 _ = Filter3(data2)
 }
 }

>>>

-- 
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/2fc7baf5-9a9a-4cd2-98d5-a11427afa39en%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread tapi...@gmail.com


On Wednesday, July 7, 2021 at 8:01:54 PM UTC-4 tapi...@gmail.com wrote:

> On Wednesday, July 7, 2021 at 12:32:38 PM UTC-4 jake...@gmail.com wrote:
>
>> It would be helpful to give more information as to why you say "This 
>> doesn't work"? 
>> But, I'm guessing that you are not seeing a decline in times when using 
>> StartTimer/StopTimer.
>>
>> It is likely that is because the copy function is fast, and frequent 
>> calls to StartTimer/StopTimer involve some error/overhead. So they are 
>> counteracting each other. Note that the documentation says the StopTimer 
>> can be used for "complex initialization", and I am guessing that a 1k copy 
>> does not count as complex. If you change the buffer size from 1024 to 
>> 1024*16 then you will see that the StartTimer/StopTimer version is in fact 
>> faster. 
>>
>> PeterGo's solution works fine, as does bench marking a larger buffer. But 
>> if your goal is to compare BenchmarkFilter3 and BenchmarkFilter4, then you 
>> could reasonably just ignore the the overhead, since it will be the same 
>> for both functions. 
>>
>
> The StartTimer/StopTimer in my example doesn't work for the "go test" 
> command hang there for ever.
>

Sorry, It doesn't really hang. It just spends much more time than I 
expected.
And it looks the result ns/op values become larger, which is also 
unexpected.
 

>
> Peter's solution exhausted my memory and hang my whole computer, and I 
> have to restart it.
>  
>
>>
>> On Wednesday, July 7, 2021 at 11:29:30 AM UTC-4 tapi...@gmail.com wrote:
>>
>>> This doesn't work:
>>>
>>> func BenchmarkFilter3(b *testing.B) {
>>> data := buildOrginalData()
>>> data2 := make([]int, len(data))
>>> b.ResetTimer()
>>> for i := 0; i < b.N; i++ {
>>> b.StopTimer()
>>> copy(data2, data)
>>> b.StartTimer()
>>> _ = Filter3(data2)
>>> }
>>> }
>>>
>>> On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:
>>>

 For example, I don't want the time consumed for "copy(data2, data)" 
 being counted.
 How to achieve this?

 func BenchmarkFilter3(b *testing.B) {
 data := buildOrginalData()
 data2 := make([]int, len(data))
 b.ResetTimer()
 for i := 0; i < b.N; i++ {
 copy(data2, data)
 _ = Filter3(data2)
 }
 }

>>>

-- 
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/c798fa64-cf7b-47ed-86d4-d53ba543597en%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread tapi...@gmail.com


On Wednesday, July 7, 2021 at 12:32:38 PM UTC-4 jake...@gmail.com wrote:

> It would be helpful to give more information as to why you say "This 
> doesn't work"? 
> But, I'm guessing that you are not seeing a decline in times when using 
> StartTimer/StopTimer.
>
> It is likely that is because the copy function is fast, and frequent calls 
> to StartTimer/StopTimer involve some error/overhead. So they are 
> counteracting each other. Note that the documentation says the StopTimer 
> can be used for "complex initialization", and I am guessing that a 1k copy 
> does not count as complex. If you change the buffer size from 1024 to 
> 1024*16 then you will see that the StartTimer/StopTimer version is in fact 
> faster. 
>
> PeterGo's solution works fine, as does bench marking a larger buffer. But 
> if your goal is to compare BenchmarkFilter3 and BenchmarkFilter4, then you 
> could reasonably just ignore the the overhead, since it will be the same 
> for both functions. 
>

The StartTimer/StopTimer in my example doesn't work for the "go test" 
command hang there for ever.

Peter's solution exhausted my memory and hang my whole computer, and I have 
to restart it.
 

>
> On Wednesday, July 7, 2021 at 11:29:30 AM UTC-4 tapi...@gmail.com wrote:
>
>> This doesn't work:
>>
>> func BenchmarkFilter3(b *testing.B) {
>> data := buildOrginalData()
>> data2 := make([]int, len(data))
>> b.ResetTimer()
>> for i := 0; i < b.N; i++ {
>> b.StopTimer()
>> copy(data2, data)
>> b.StartTimer()
>> _ = Filter3(data2)
>> }
>> }
>>
>> On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:
>>
>>>
>>> For example, I don't want the time consumed for "copy(data2, data)" 
>>> being counted.
>>> How to achieve this?
>>>
>>> func BenchmarkFilter3(b *testing.B) {
>>> data := buildOrginalData()
>>> data2 := make([]int, len(data))
>>> b.ResetTimer()
>>> for i := 0; i < b.N; i++ {
>>> copy(data2, data)
>>> _ = Filter3(data2)
>>> }
>>> }
>>>
>>

-- 
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/fcc1dd38-e97e-4d8e-ad76-fa4b2968311bn%40googlegroups.com.


[go-nuts] [security] Go 1.16.6 and Go 1.15.14 pre-announcement

2021-07-07 Thread Filippo Valsorda
Hello gophers,

We plan to issue Go 1.16.6 and Go 1.15.14 on Monday, July 12.
These are minor releases that include security fixes to the standard
library.

Following our new security policy , this is
the pre-announcement of those releases.

Alla prossima,
Filippo on behalf of the Go team

-- 
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/CA%2B2K_KqziJNAeiL1ZP4ryYHRtS6DAUp%2B2zgFkd%3DyDuS3LGuDUw%40mail.gmail.com.


[go-nuts] C Third Party Lib CGO

2021-07-07 Thread snmed

Hi all

Once again I have a 3th party library which looks like this example: 
https://play.golang.org/p/Ue9yQ8s8Ymq and I need it to integrate in our go 
tool. The example is working but is still get the warning "
possible misuse of unsafe.Pointer". 

So my questions are:

   1. Can I use uintptr to hold the void pointer and pass it around go 
   functions?
   2. Can I ignore the warning "possible misuse of unsafe.pointer"?
   3. If not, what would be the proper approach for this example?

Any help is much appreciated...
Sandro


-- 
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/964e1e57-ff6f-4f3e-8f40-981a3966e734n%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread jake...@gmail.com
It would be helpful to give more information as to why you say "This 
doesn't work"? 
But, I'm guessing that you are not seeing a decline in times when using 
StartTimer/StopTimer.

It is likely that is because the copy function is fast, and frequent calls 
to StartTimer/StopTimer involve some error/overhead. So they are 
counteracting each other. Note that the documentation says the StopTimer 
can be used for "complex initialization", and I am guessing that a 1k copy 
does not count as complex. If you change the buffer size from 1024 to 
1024*16 then you will see that the StartTimer/StopTimer version is in fact 
faster. 

PeterGo's solution works fine, as does bench marking a larger buffer. But 
if your goal is to compare BenchmarkFilter3 and BenchmarkFilter4, then you 
could reasonably just ignore the the overhead, since it will be the same 
for both functions. 

On Wednesday, July 7, 2021 at 11:29:30 AM UTC-4 tapi...@gmail.com wrote:

> This doesn't work:
>
> func BenchmarkFilter3(b *testing.B) {
> data := buildOrginalData()
> data2 := make([]int, len(data))
> b.ResetTimer()
> for i := 0; i < b.N; i++ {
> b.StopTimer()
> copy(data2, data)
> b.StartTimer()
> _ = Filter3(data2)
> }
> }
>
> On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:
>
>>
>> For example, I don't want the time consumed for "copy(data2, data)" being 
>> counted.
>> How to achieve this?
>>
>> func BenchmarkFilter3(b *testing.B) {
>> data := buildOrginalData()
>> data2 := make([]int, len(data))
>> b.ResetTimer()
>> for i := 0; i < b.N; i++ {
>> copy(data2, data)
>> _ = Filter3(data2)
>> }
>> }
>>
>

-- 
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/c1f156d5-e582-4932-88f8-a2df6c987d85n%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread peterGo
$ go test copy_test.go -bench=. -benchmem
BenchmarkFilter3-4  358167  3209 ns/op  8192 B/op  1 allocs/op
$

package main

import "testing"

func Filter3(a []int) []int {
s := make([]int, len(a))
for i := range s {
s[i] += 42
}
return nil
}

func buildOrginalData() []int {
data := make([]int, 1024)
for i := range data {
data[i] = i
}
return data
}

func BenchmarkFilter3(b *testing.B) {
data := buildOrginalData()
copies := make([][]int, b.N)
for i := range copies {
copies[i] = make([]int, len(data))
copy(copies[i], data)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = Filter3(copies[i])
}
}

https://play.golang.org/p/tzBl8VBve3D

Peter


On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:

>
> For example, I don't want the time consumed for "copy(data2, data)" being 
> counted.
> How to achieve this?
>
> func BenchmarkFilter3(b *testing.B) {
> data := buildOrginalData()
> data2 := make([]int, len(data))
> b.ResetTimer()
> for i := 0; i < b.N; i++ {
> copy(data2, data)
> _ = Filter3(data2)
> }
> }
>

-- 
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/0b0da32a-f13d-4a0c-aa57-48b92d41d102n%40googlegroups.com.


[go-nuts] Re: How to pause/restart timer in a benchmark loop?

2021-07-07 Thread tapi...@gmail.com
This doesn't work:

func BenchmarkFilter3(b *testing.B) {
data := buildOrginalData()
data2 := make([]int, len(data))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
copy(data2, data)
b.StartTimer()
_ = Filter3(data2)
}
}

On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote:

>
> For example, I don't want the time consumed for "copy(data2, data)" being 
> counted.
> How to achieve this?
>
> func BenchmarkFilter3(b *testing.B) {
> data := buildOrginalData()
> data2 := make([]int, len(data))
> b.ResetTimer()
> for i := 0; i < b.N; i++ {
> copy(data2, data)
> _ = Filter3(data2)
> }
> }
>

-- 
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/42fd1278-d714-48bb-9836-ec5fb385b16an%40googlegroups.com.


[go-nuts] How to pause/restart timer in a benchmark loop?

2021-07-07 Thread tapi...@gmail.com

For example, I don't want the time consumed for "copy(data2, data)" being 
counted.
How to achieve this?

func BenchmarkFilter3(b *testing.B) {
data := buildOrginalData()
data2 := make([]int, len(data))
b.ResetTimer()
for i := 0; i < b.N; i++ {
copy(data2, data)
_ = Filter3(data2)
}
}

-- 
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/60c977f7-25e9-4f82-abb0-1798398fa62en%40googlegroups.com.


[go-nuts] Re: Surprising benchmark result

2021-07-07 Thread tapi...@gmail.com
It is found that the test file is not written correctly.
The filtered data should be reset in each loop.
The corrected one: https://play.golang.org/p/yJMweZLIXAz 


;D

On Monday, June 7, 2021 at 10:57:19 AM UTC-4 tapi...@gmail.com wrote:

>
> The code: https://play.golang.org/p/DxUj6kBqf8k
>
> The Filter4 function has one more assignment statement than Filter3.
> But the benchmark result shows Filter4 is faster than Filter3.
>
> The result:
>
> cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
> BenchmarkFilter3-43575656   980.2 ns/op   0 
> B/op   0 allocs/op
> BenchmarkFilter4-43956533   916.8 ns/op   0 
> B/op   0 allocs/op
>
>
>

-- 
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/5f7a9f11-d43a-4bc1-88c1-758b52d4dd7bn%40googlegroups.com.


Re: [go-nuts] Reason to use different address space in gollvm

2021-07-07 Thread 'Than McIntosh' via golang-nuts
Hi again,

Sorry for the delay, I have been offline for a while.

You wrote:
>Regarding address spaces, I saw that there is a pass to remove address
space casts. But if I generate IR using `llvm-goc -dump-ir -enable-gc=1
test.go` for the following go file, I still can see the addrspacecast
instruction. What is the reason to see that addrspacecast? I feel that pass
is not running. Can you help me to understand this problem?

A couple of things on this.

First, the "-dump-ir" option to llvm-goc shows the LLVM IR after the front
end and bridge are done with creating it -- at this point no LLVM passes
will have been run, so you would not expect to see any address space casts
removed.  Probably what you want here is "-emit-llvm", which will show LLVM
IR after all the various module and function passes have run (before the
switch to machine-dependent IR). Example:

 $ llvm-goc -S -emit-llvm -enable-gc=1 test.go
 $ cat test.ll
 ...
 $

A second thing is that the cast-removal pass you mention isn't removing
every cast, only casts on initialized global variables fed with constants.
If you look at this source code

https://go.googlesource.com/gollvm/+/38bada572789a19cf881201c923e6b56ed32ae53/passes/RemoveAddrSpace.cpp#95

you can see that it's visiting only initialized globals. If you want to
examples of cast removal, try running your compile on a larger and more
interesting test case, like

  https://golang.org/test/method5.go

In general if you are unsure about whether a pass is running and/or what
the effects of the pass are, there are developer options you can try (note:
available only in a pure debug build) that can show you more. Example:

 # Dump LLVM IR before a pass
 $ ./bin/llvm-goc -O2 -c -emit-llvm -S -enable-gc=1 -mllvm
-print-before=remove-addrspacecast test.go 1> before.dump.txt 2>&1

 # Dump LLVM IR after a pass
 $ ./bin/llvm-goc -O2 -c -emit-llvm -S -enable-gc=1 -mllvm
-print-after=remove-addrspacecast test.go 1> after.dump.txt 2>&1

Hope this helps.

Thanks, Than

On Mon, Jul 5, 2021 at 3:08 AM Kavindu Gimhan Zoysa 
wrote:

> Hi,
>
> Regarding address spaces, I saw that there is a pass to remove address
> space casts. But if I generate IR using `*llvm-goc -dump-ir -enable-gc=1
> test.go*` for the following go file, I still can see the *addrspacecast*
> instruction. What is the reason to see that *addrspacecast? *I feel that
> pass is not running. Can you help me to understand this problem?
>
>
> *package main*
>
> *func main() {*
> *   _ = stackIt2()*
> *}*
> *//go:noinline*
> *func stackIt2() *int {*
> *   y := 2*
> *   res := y * 2*
> *   return *
> *}*
>
> Thank you,
> Kavindu
> On Tuesday, 29 June 2021 at 18:22:14 UTC+5:30 th...@google.com wrote:
>
>> See https://llvm.org/docs/Statepoints.html for more on this.
>>
>> Thanks, Than
>>
>>
>> On Mon, Jun 28, 2021 at 5:40 AM Kavindu Gimhan Zoysa 
>> wrote:
>>
>>> Hi all,
>>>
>>> Can you please explain the reason to use different address space when GC
>>> is enabled as shown in the below line?
>>>
>>>
>>> https://go.googlesource.com/gollvm/+/refs/heads/master/driver/CompileGo.cpp#559
>>>
>>> Thank you,
>>> Kavindu
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/d95934ca-4488-4071-8c07-bb33122be387n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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/c26ff4b9-84a9-4aa2-a450-5d1796aba1c0n%40googlegroups.com
> 
> .
>

-- 
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/CA%2BUr55Gqi9p4jDbiUWAAE_amhMsrCLf4gUc5-XTR8wd4pVjMEg%40mail.gmail.com.


Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Levieux Michel
You cannot *per se* convert an interface or a struct to a builtin like
[]byte
You might wanna have a look at the Bytes method
 of *bytes.Buffer, which
returns the internal buffer of the type as a slice of bytes. Normally that
would have been a good exercise to let you find it yourself, and I don't
know if it is really "help" to give it to you directly, but as I said, once
you are done with your small tool, the next step for you will be to go back
from the basic Go constructs :)

Glad I could help, and don't bother with the comments, the best "thank you"
I can wish for is that we continue learning together ;)
Hope the following adventures of your Go journey are as interesting as they
are for me!

Cheers

Le mer. 7 juil. 2021 à 15:08, LetGo  a écrit :

> Thanks for your answer!(:
> You are right, but I just wanted to have this one little tool in Go  and I
> have never thought that could be that hard... ahahah
>
> By the way, it works as you said, it fixed the error! ( obviously.. ) the
> only thing left is to convert type *bytes.Buffer to []byte * I think* and
> then I will be almost done.
> Im already searching how to do that.
>
> Once it will work as I wish, I will add your names to my comments ( I
> think this is better than any "thank you" ) in the code, to remind me of
> your kind help(:
>
>
>
> Il giorno mercoledì 7 luglio 2021 alle 14:01:33 UTC+2 mlevi...@gmail.com
> ha scritto:
>
>> [Sorry forgot to hit "Reply all"]
>>
>> Are you trying to cast cmd.Stdout here?
>> What you can do is:
>> buf := new(bytes.Buffer)
>> cmd.Stdout = buf // buf is an io.Writer so this is fine
>>
>> but I don't get the point of the data := foo?
>>
>> Maybe, before trying to convert a whole complex program in Python to a
>> whole working program in Go, you should take time to familiarize yourself
>> with the language.
>> Go through the Go tour , read a
>> little of the specs, have yourself code some small, simple programs that
>> don't require using lots of std packages at once...
>>
>> Once you are familiar with the language constructs, which I have to say
>> are pretty different from Python's, you will have a better understanding of
>> where to start and how to implement your program. Otherwise I think this
>> will all only get you confused.
>> And understanding at least the important basics of Go will help you
>> explain your pain points here, if any remains :)
>>
>> Hope this helps,
>>
>> Le mer. 7 juil. 2021 à 12:41, LetGo  a écrit :
>>
>>> One of these is this:
>>> ...
>>>buf := new(bytes.Buffer)
>>> foo := buf(cmd.Stdout) // this line is 87
>>> data := foo
>>> var i int
>>> ...
>>>
>>> pkg/conn.go:87:20: cannot call non-function buf (type *bytes.Buffer)
>>> Il giorno mercoledì 7 luglio 2021 alle 12:10:03 UTC+2 LetGo ha scritto:
>>>
 I tried also both of them, but I got stuck into a loop of errors
 again.. probably I coded in the wrong way

 Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha
 scritto:

> It makes no sense to convert an io.Writer to a string.
>
> io.Writer is an interface: any type which has a Write() method.  So
> you can pass a string *to* a writer, to get it written somewhere, by
> calling the Write() method.  In general, you can't get a string *from* a
> writer.  If you google "go io.Writer" you'll get lots of tutorials and
> examples.
>
> Depending on your application though, you might want to create a
> bytes.Buffer  or strings.Builder
>  object, both of which are
> an io.Writer.  The written data gets appended to a buffer that you can 
> read
> later.
>
> On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:
>
>> Thanks for your answer!(:
>> You are right, sorry!
>> This is the code: https://play.golang.org/p/zEZ2HIUNffs
>>
>> About the lines, wow! Yes, you got them! ahah
>> About the errors, I tried to convert ( cmd.Stdout ) io.Write to
>> bytes/ strings, but.. I have then entered into a loop of errors...
>>
>>
>>
>> Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha
>> scritto:
>>
>>> You haven't shown which lines 75, 76 and 83 correspond to.  It's
>>> easier if you put the whole code on play.golang.org, and we'll be
>>> able to point to the error.
>>>
>>> But I'm guessing it's this:
>>>  data := cmd.Stdout
>>> ...
>>> n := int(math.Min(float64(rand.Intn(len(data))),
>>> float64(len(data  << line 75?
>>> d := data[i : i+n]  << line 76?
>>> ...
>>> if i >= len(data) {   << line 83?
>>>
>>> If I'm right, the compiler is saying: cmd.Stdout (which you assigned
>>> to 'data') is of type io.Writer.  It's not a string; you can't take
>>> len(...) of an 

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
Thanks for your answer!(:
You are right, but I just wanted to have this one little tool in Go  and I 
have never thought that could be that hard... ahahah

By the way, it works as you said, it fixed the error! ( obviously.. ) the 
only thing left is to convert type *bytes.Buffer to []byte * I think* and 
then I will be almost done.
Im already searching how to do that.

Once it will work as I wish, I will add your names to my comments ( I think 
this is better than any "thank you" ) in the code, to remind me of your 
kind help(:



Il giorno mercoledì 7 luglio 2021 alle 14:01:33 UTC+2 mlevi...@gmail.com ha 
scritto:

> [Sorry forgot to hit "Reply all"]
>
> Are you trying to cast cmd.Stdout here?
> What you can do is:
> buf := new(bytes.Buffer)
> cmd.Stdout = buf // buf is an io.Writer so this is fine
>
> but I don't get the point of the data := foo?
>
> Maybe, before trying to convert a whole complex program in Python to a 
> whole working program in Go, you should take time to familiarize yourself 
> with the language.
> Go through the Go tour , read a little 
> of the specs, have yourself code some small, simple programs that don't 
> require using lots of std packages at once...
>
> Once you are familiar with the language constructs, which I have to say 
> are pretty different from Python's, you will have a better understanding of 
> where to start and how to implement your program. Otherwise I think this 
> will all only get you confused.
> And understanding at least the important basics of Go will help you 
> explain your pain points here, if any remains :)
>
> Hope this helps,
>
> Le mer. 7 juil. 2021 à 12:41, LetGo  a écrit :
>
>> One of these is this:
>> ...
>>buf := new(bytes.Buffer) 
>> foo := buf(cmd.Stdout) // this line is 87
>> data := foo
>> var i int
>> ...
>>
>> pkg/conn.go:87:20: cannot call non-function buf (type *bytes.Buffer)
>> Il giorno mercoledì 7 luglio 2021 alle 12:10:03 UTC+2 LetGo ha scritto:
>>
>>> I tried also both of them, but I got stuck into a loop of errors again.. 
>>> probably I coded in the wrong way
>>>
>>> Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha 
>>> scritto:
>>>
 It makes no sense to convert an io.Writer to a string.

 io.Writer is an interface: any type which has a Write() method.  So you 
 can pass a string *to* a writer, to get it written somewhere, by calling 
 the Write() method.  In general, you can't get a string *from* a writer.  
 If you google "go io.Writer" you'll get lots of tutorials and examples.

 Depending on your application though, you might want to create a 
 bytes.Buffer  or strings.Builder 
  object, both of which are an 
 io.Writer.  The written data gets appended to a buffer that you can read 
 later.

 On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:

> Thanks for your answer!(:
> You are right, sorry!
> This is the code: https://play.golang.org/p/zEZ2HIUNffs
>
> About the lines, wow! Yes, you got them! ahah
> About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ 
> strings, but.. I have then entered into a loop of errors...
>
>
>
> Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha 
> scritto:
>
>> You haven't shown which lines 75, 76 and 83 correspond to.  It's 
>> easier if you put the whole code on play.golang.org, and we'll be 
>> able to point to the error.  
>>
>> But I'm guessing it's this:
>>  data := cmd.Stdout
>> ...
>> n := int(math.Min(float64(rand.Intn(len(data))), 
>> float64(len(data  << line 75?
>> d := data[i : i+n]  << line 76?
>> ...
>> if i >= len(data) {   << line 83?
>>
>> If I'm right, the compiler is saying: cmd.Stdout (which you assigned 
>> to 'data') is of type io.Writer.  It's not a string; you can't take 
>> len(...) of an io.Writer, nor can you slice it.
>>
>> On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:
>>
>>> I think I made some progress I think. Is it right what I'm doing 
>>> ?
>>>
>>> 
>>> cmd.Stdin = conn
>>> // cmd.Stdout = conn
>>> // data := []byte(cmd.Stdout)
>>> data := cmd.Stdout
>>> var i int
>>> for {
>>> n := int(math.Min(float64(rand.Intn(len(data))), 
>>> float64(len(data
>>> d := data[i : i+n]
>>> i += n
>>> time.Sleep(400 * time.Millisecond)
>>> d = conn
>>>
>>> if i >= len(data) {
>>> break
>>> }
>>> }
>>> cmd.Stderr = conn
>>> cmd.Run()
>>> 
>>>
>>> But when I try to build I get these errors:
>>>
>>> conn.go:75:46: invalid 

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Levieux Michel
[Sorry forgot to hit "Reply all"]

Are you trying to cast cmd.Stdout here?
What you can do is:
buf := new(bytes.Buffer)
cmd.Stdout = buf // buf is an io.Writer so this is fine

but I don't get the point of the data := foo?

Maybe, before trying to convert a whole complex program in Python to a
whole working program in Go, you should take time to familiarize yourself
with the language.
Go through the Go tour , read a little
of the specs, have yourself code some small, simple programs that don't
require using lots of std packages at once...

Once you are familiar with the language constructs, which I have to say are
pretty different from Python's, you will have a better understanding of
where to start and how to implement your program. Otherwise I think this
will all only get you confused.
And understanding at least the important basics of Go will help you explain
your pain points here, if any remains :)

Hope this helps,

Le mer. 7 juil. 2021 à 12:41, LetGo  a écrit :

> One of these is this:
> ...
>buf := new(bytes.Buffer)
> foo := buf(cmd.Stdout) // this line is 87
> data := foo
> var i int
> ...
>
> pkg/conn.go:87:20: cannot call non-function buf (type *bytes.Buffer)
> Il giorno mercoledì 7 luglio 2021 alle 12:10:03 UTC+2 LetGo ha scritto:
>
>> I tried also both of them, but I got stuck into a loop of errors again..
>> probably I coded in the wrong way
>>
>> Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha
>> scritto:
>>
>>> It makes no sense to convert an io.Writer to a string.
>>>
>>> io.Writer is an interface: any type which has a Write() method.  So you
>>> can pass a string *to* a writer, to get it written somewhere, by calling
>>> the Write() method.  In general, you can't get a string *from* a writer.
>>> If you google "go io.Writer" you'll get lots of tutorials and examples.
>>>
>>> Depending on your application though, you might want to create a
>>> bytes.Buffer  or strings.Builder
>>>  object, both of which are an
>>> io.Writer.  The written data gets appended to a buffer that you can read
>>> later.
>>>
>>> On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:
>>>
 Thanks for your answer!(:
 You are right, sorry!
 This is the code: https://play.golang.org/p/zEZ2HIUNffs

 About the lines, wow! Yes, you got them! ahah
 About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/
 strings, but.. I have then entered into a loop of errors...



 Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha
 scritto:

> You haven't shown which lines 75, 76 and 83 correspond to.  It's
> easier if you put the whole code on play.golang.org, and we'll be
> able to point to the error.
>
> But I'm guessing it's this:
>  data := cmd.Stdout
> ...
> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data
> << line 75?
> d := data[i : i+n]  << line 76?
> ...
> if i >= len(data) {   << line 83?
>
> If I'm right, the compiler is saying: cmd.Stdout (which you assigned
> to 'data') is of type io.Writer.  It's not a string; you can't take
> len(...) of an io.Writer, nor can you slice it.
>
> On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:
>
>> I think I made some progress I think. Is it right what I'm doing ?
>>
>> 
>> cmd.Stdin = conn
>> // cmd.Stdout = conn
>> // data := []byte(cmd.Stdout)
>> data := cmd.Stdout
>> var i int
>> for {
>> n := int(math.Min(float64(rand.Intn(len(data))),
>> float64(len(data
>> d := data[i : i+n]
>> i += n
>> time.Sleep(400 * time.Millisecond)
>> d = conn
>>
>> if i >= len(data) {
>> break
>> }
>> }
>> cmd.Stderr = conn
>> cmd.Run()
>> 
>>
>> But when I try to build I get these errors:
>>
>> conn.go:75:46: invalid argument data (type io.Writer) for len
>> conn.go:76:16: cannot slice data (type io.Writer)
>> conn.go:83:22: invalid argument data (type io.Writer) for len
>>
>>
>>
>>
>>
>>
>>
>>
>> Il giorno martedì 29 giugno 2021 alle 19:37:04 UTC+2 LetGo ha scritto:
>>
>>> Thank you guys for all your answers and suggestions!
>>> I really appreciate!
>>> Sorry about the screenshots, it was the only way to make the packets
>>> "human readable"
>>> How could you code that kind of implementation based on your
>>> knowledge and skill?
>>> I have noone of these in golang ahah as I said, im too newbie to do
>>> all this alone!
>>> Also not working examples ( if they throw an error I don't care,
>>> based on my code are fine!

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
One of these is this:
...
   buf := new(bytes.Buffer) 
foo := buf(cmd.Stdout) // this line is 87
data := foo
var i int
...

pkg/conn.go:87:20: cannot call non-function buf (type *bytes.Buffer)
Il giorno mercoledì 7 luglio 2021 alle 12:10:03 UTC+2 LetGo ha scritto:

> I tried also both of them, but I got stuck into a loop of errors again.. 
> probably I coded in the wrong way
>
> Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha 
> scritto:
>
>> It makes no sense to convert an io.Writer to a string.
>>
>> io.Writer is an interface: any type which has a Write() method.  So you 
>> can pass a string *to* a writer, to get it written somewhere, by calling 
>> the Write() method.  In general, you can't get a string *from* a writer.  
>> If you google "go io.Writer" you'll get lots of tutorials and examples.
>>
>> Depending on your application though, you might want to create a 
>> bytes.Buffer  or strings.Builder 
>>  object, both of which are an 
>> io.Writer.  The written data gets appended to a buffer that you can read 
>> later.
>>
>> On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:
>>
>>> Thanks for your answer!(:
>>> You are right, sorry!
>>> This is the code: https://play.golang.org/p/zEZ2HIUNffs
>>>
>>> About the lines, wow! Yes, you got them! ahah
>>> About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ 
>>> strings, but.. I have then entered into a loop of errors...
>>>
>>>
>>>
>>> Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha 
>>> scritto:
>>>
 You haven't shown which lines 75, 76 and 83 correspond to.  It's easier 
 if you put the whole code on play.golang.org, and we'll be able to 
 point to the error.  

 But I'm guessing it's this:
  data := cmd.Stdout
 ...
 n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data  
 << line 75?
 d := data[i : i+n]  << line 76?
 ...
 if i >= len(data) {   << line 83?

 If I'm right, the compiler is saying: cmd.Stdout (which you assigned to 
 'data') is of type io.Writer.  It's not a string; you can't take len(...) 
 of an io.Writer, nor can you slice it.

 On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:

> I think I made some progress I think. Is it right what I'm doing ?
>
> 
> cmd.Stdin = conn
> // cmd.Stdout = conn
> // data := []byte(cmd.Stdout)
> data := cmd.Stdout
> var i int
> for {
> n := int(math.Min(float64(rand.Intn(len(data))), 
> float64(len(data
> d := data[i : i+n]
> i += n
> time.Sleep(400 * time.Millisecond)
> d = conn
>
> if i >= len(data) {
> break
> }
> }
> cmd.Stderr = conn
> cmd.Run()
> 
>
> But when I try to build I get these errors:
>
> conn.go:75:46: invalid argument data (type io.Writer) for len
> conn.go:76:16: cannot slice data (type io.Writer)
> conn.go:83:22: invalid argument data (type io.Writer) for len
>
>
>
>
>
>
>
>
> Il giorno martedì 29 giugno 2021 alle 19:37:04 UTC+2 LetGo ha scritto:
>
>> Thank you guys for all your answers and suggestions!
>> I really appreciate!
>> Sorry about the screenshots, it was the only way to make the packets 
>> "human readable"
>> How could you code that kind of implementation based on your 
>> knowledge and skill?
>> I have noone of these in golang ahah as I said, im too newbie to do 
>> all this alone!
>> Also not working examples ( if they throw an error I don't care, 
>> based on my code are fine!
>> These examples could rapresent a great start from me!(:
>>
>>
>> Il giorno martedì 29 giugno 2021 alle 19:00:06 UTC+2 
>> jesper.lou...@gmail.com ha scritto:
>>
>>> On Tue, Jun 29, 2021 at 5:24 PM LetGo  wrote:
>>>
 Thanks for the answer! (:
 In python it was straightforward to implement and it works like a 
 charm. It sends small packets with delay between each other without 
 even 
 care if it is UDP or TCP:


>>> Beware! This is an assumption that will break at some point in time. 
>>> Currently the delay and the OS makes things straightforward for you. 
>>> But 
>>> TCP doesn't behave like you expect, and you are very likely to run into 
>>> trouble if the machine, the network, or the system starts taking 
>>> additional 
>>> load.
>>>
>>> You need to frame the data. A good way is to use 4 bytes as a size 
>>> (unsigned 32 bit integer), followed by a payload of that size. You can 
>>> then 
>>> avoid this becoming an uncontrolled explosion in your 

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
I tried also both of them, but I got stuck into a loop of errors again.. 
probably I coded in the wrong way

Il giorno mercoledì 7 luglio 2021 alle 11:50:51 UTC+2 Brian Candler ha 
scritto:

> It makes no sense to convert an io.Writer to a string.
>
> io.Writer is an interface: any type which has a Write() method.  So you 
> can pass a string *to* a writer, to get it written somewhere, by calling 
> the Write() method.  In general, you can't get a string *from* a writer.  
> If you google "go io.Writer" you'll get lots of tutorials and examples.
>
> Depending on your application though, you might want to create a 
> bytes.Buffer  or strings.Builder 
>  object, both of which are an 
> io.Writer.  The written data gets appended to a buffer that you can read 
> later.
>
> On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:
>
>> Thanks for your answer!(:
>> You are right, sorry!
>> This is the code: https://play.golang.org/p/zEZ2HIUNffs
>>
>> About the lines, wow! Yes, you got them! ahah
>> About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ 
>> strings, but.. I have then entered into a loop of errors...
>>
>>
>>
>> Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha 
>> scritto:
>>
>>> You haven't shown which lines 75, 76 and 83 correspond to.  It's easier 
>>> if you put the whole code on play.golang.org, and we'll be able to 
>>> point to the error.  
>>>
>>> But I'm guessing it's this:
>>>  data := cmd.Stdout
>>> ...
>>> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data  
>>> << line 75?
>>> d := data[i : i+n]  << line 76?
>>> ...
>>> if i >= len(data) {   << line 83?
>>>
>>> If I'm right, the compiler is saying: cmd.Stdout (which you assigned to 
>>> 'data') is of type io.Writer.  It's not a string; you can't take len(...) 
>>> of an io.Writer, nor can you slice it.
>>>
>>> On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:
>>>
 I think I made some progress I think. Is it right what I'm doing ?

 
 cmd.Stdin = conn
 // cmd.Stdout = conn
 // data := []byte(cmd.Stdout)
 data := cmd.Stdout
 var i int
 for {
 n := int(math.Min(float64(rand.Intn(len(data))), 
 float64(len(data
 d := data[i : i+n]
 i += n
 time.Sleep(400 * time.Millisecond)
 d = conn

 if i >= len(data) {
 break
 }
 }
 cmd.Stderr = conn
 cmd.Run()
 

 But when I try to build I get these errors:

 conn.go:75:46: invalid argument data (type io.Writer) for len
 conn.go:76:16: cannot slice data (type io.Writer)
 conn.go:83:22: invalid argument data (type io.Writer) for len








 Il giorno martedì 29 giugno 2021 alle 19:37:04 UTC+2 LetGo ha scritto:

> Thank you guys for all your answers and suggestions!
> I really appreciate!
> Sorry about the screenshots, it was the only way to make the packets 
> "human readable"
> How could you code that kind of implementation based on your knowledge 
> and skill?
> I have noone of these in golang ahah as I said, im too newbie to do 
> all this alone!
> Also not working examples ( if they throw an error I don't care, based 
> on my code are fine!
> These examples could rapresent a great start from me!(:
>
>
> Il giorno martedì 29 giugno 2021 alle 19:00:06 UTC+2 
> jesper.lou...@gmail.com ha scritto:
>
>> On Tue, Jun 29, 2021 at 5:24 PM LetGo  wrote:
>>
>>> Thanks for the answer! (:
>>> In python it was straightforward to implement and it works like a 
>>> charm. It sends small packets with delay between each other without 
>>> even 
>>> care if it is UDP or TCP:
>>>
>>>
>> Beware! This is an assumption that will break at some point in time. 
>> Currently the delay and the OS makes things straightforward for you. But 
>> TCP doesn't behave like you expect, and you are very likely to run into 
>> trouble if the machine, the network, or the system starts taking 
>> additional 
>> load.
>>
>> You need to frame the data. A good way is to use 4 bytes as a size 
>> (unsigned 32 bit integer), followed by a payload of that size. You can 
>> then 
>> avoid this becoming an uncontrolled explosion in your software at a 
>> later 
>> date. You can also close connections early if too large messages get 
>> sent, 
>> etc.
>>
>>

-- 
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 

Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread Brian Candler
It makes no sense to convert an io.Writer to a string.

io.Writer is an interface: any type which has a Write() method.  So you can 
pass a string *to* a writer, to get it written somewhere, by calling the 
Write() method.  In general, you can't get a string *from* a writer.  If 
you google "go io.Writer" you'll get lots of tutorials and examples.

Depending on your application though, you might want to create a 
bytes.Buffer  or strings.Builder 
 object, both of which are an 
io.Writer.  The written data gets appended to a buffer that you can read 
later.

On Wednesday, 7 July 2021 at 10:07:19 UTC+1 LetGo wrote:

> Thanks for your answer!(:
> You are right, sorry!
> This is the code: https://play.golang.org/p/zEZ2HIUNffs
>
> About the lines, wow! Yes, you got them! ahah
> About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ 
> strings, but.. I have then entered into a loop of errors...
>
>
>
> Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha 
> scritto:
>
>> You haven't shown which lines 75, 76 and 83 correspond to.  It's easier 
>> if you put the whole code on play.golang.org, and we'll be able to point 
>> to the error.  
>>
>> But I'm guessing it's this:
>>  data := cmd.Stdout
>> ...
>> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data  << 
>> line 75?
>> d := data[i : i+n]  << line 76?
>> ...
>> if i >= len(data) {   << line 83?
>>
>> If I'm right, the compiler is saying: cmd.Stdout (which you assigned to 
>> 'data') is of type io.Writer.  It's not a string; you can't take len(...) 
>> of an io.Writer, nor can you slice it.
>>
>> On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:
>>
>>> I think I made some progress I think. Is it right what I'm doing ?
>>>
>>> 
>>> cmd.Stdin = conn
>>> // cmd.Stdout = conn
>>> // data := []byte(cmd.Stdout)
>>> data := cmd.Stdout
>>> var i int
>>> for {
>>> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data
>>> d := data[i : i+n]
>>> i += n
>>> time.Sleep(400 * time.Millisecond)
>>> d = conn
>>>
>>> if i >= len(data) {
>>> break
>>> }
>>> }
>>> cmd.Stderr = conn
>>> cmd.Run()
>>> 
>>>
>>> But when I try to build I get these errors:
>>>
>>> conn.go:75:46: invalid argument data (type io.Writer) for len
>>> conn.go:76:16: cannot slice data (type io.Writer)
>>> conn.go:83:22: invalid argument data (type io.Writer) for len
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Il giorno martedì 29 giugno 2021 alle 19:37:04 UTC+2 LetGo ha scritto:
>>>
 Thank you guys for all your answers and suggestions!
 I really appreciate!
 Sorry about the screenshots, it was the only way to make the packets 
 "human readable"
 How could you code that kind of implementation based on your knowledge 
 and skill?
 I have noone of these in golang ahah as I said, im too newbie to do all 
 this alone!
 Also not working examples ( if they throw an error I don't care, based 
 on my code are fine!
 These examples could rapresent a great start from me!(:


 Il giorno martedì 29 giugno 2021 alle 19:00:06 UTC+2 
 jesper.lou...@gmail.com ha scritto:

> On Tue, Jun 29, 2021 at 5:24 PM LetGo  wrote:
>
>> Thanks for the answer! (:
>> In python it was straightforward to implement and it works like a 
>> charm. It sends small packets with delay between each other without even 
>> care if it is UDP or TCP:
>>
>>
> Beware! This is an assumption that will break at some point in time. 
> Currently the delay and the OS makes things straightforward for you. But 
> TCP doesn't behave like you expect, and you are very likely to run into 
> trouble if the machine, the network, or the system starts taking 
> additional 
> load.
>
> You need to frame the data. A good way is to use 4 bytes as a size 
> (unsigned 32 bit integer), followed by a payload of that size. You can 
> then 
> avoid this becoming an uncontrolled explosion in your software at a later 
> date. You can also close connections early if too large messages get 
> sent, 
> etc.
>
>

-- 
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/0d58e9b6-66e7-4fdf-a7f2-d19afd5f55c2n%40googlegroups.com.


Re: [go-nuts] Re: How to implement this in golang?

2021-07-07 Thread LetGo
Thanks for your answer!(:
You are right, sorry!
This is the code: https://play.golang.org/p/zEZ2HIUNffs

About the lines, wow! Yes, you got them! ahah
About the errors, I tried to convert ( cmd.Stdout ) io.Write to bytes/ 
strings, but.. I have then entered into a loop of errors...



Il giorno martedì 6 luglio 2021 alle 21:32:10 UTC+2 Brian Candler ha 
scritto:

> You haven't shown which lines 75, 76 and 83 correspond to.  It's easier if 
> you put the whole code on play.golang.org, and we'll be able to point to 
> the error.  
>
> But I'm guessing it's this:
>  data := cmd.Stdout
> ...
> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data  << 
> line 75?
> d := data[i : i+n]  << line 76?
> ...
> if i >= len(data) {   << line 83?
>
> If I'm right, the compiler is saying: cmd.Stdout (which you assigned to 
> 'data') is of type io.Writer.  It's not a string; you can't take len(...) 
> of an io.Writer, nor can you slice it.
>
> On Tuesday, 6 July 2021 at 16:03:26 UTC+1 LetGo wrote:
>
>> I think I made some progress I think. Is it right what I'm doing ?
>>
>> 
>> cmd.Stdin = conn
>> // cmd.Stdout = conn
>> // data := []byte(cmd.Stdout)
>> data := cmd.Stdout
>> var i int
>> for {
>> n := int(math.Min(float64(rand.Intn(len(data))), float64(len(data
>> d := data[i : i+n]
>> i += n
>> time.Sleep(400 * time.Millisecond)
>> d = conn
>>
>> if i >= len(data) {
>> break
>> }
>> }
>> cmd.Stderr = conn
>> cmd.Run()
>> 
>>
>> But when I try to build I get these errors:
>>
>> conn.go:75:46: invalid argument data (type io.Writer) for len
>> conn.go:76:16: cannot slice data (type io.Writer)
>> conn.go:83:22: invalid argument data (type io.Writer) for len
>>
>>
>>
>>
>>
>>
>>
>>
>> Il giorno martedì 29 giugno 2021 alle 19:37:04 UTC+2 LetGo ha scritto:
>>
>>> Thank you guys for all your answers and suggestions!
>>> I really appreciate!
>>> Sorry about the screenshots, it was the only way to make the packets 
>>> "human readable"
>>> How could you code that kind of implementation based on your knowledge 
>>> and skill?
>>> I have noone of these in golang ahah as I said, im too newbie to do all 
>>> this alone!
>>> Also not working examples ( if they throw an error I don't care, based 
>>> on my code are fine!
>>> These examples could rapresent a great start from me!(:
>>>
>>>
>>> Il giorno martedì 29 giugno 2021 alle 19:00:06 UTC+2 
>>> jesper.lou...@gmail.com ha scritto:
>>>
 On Tue, Jun 29, 2021 at 5:24 PM LetGo  wrote:

> Thanks for the answer! (:
> In python it was straightforward to implement and it works like a 
> charm. It sends small packets with delay between each other without even 
> care if it is UDP or TCP:
>
>
 Beware! This is an assumption that will break at some point in time. 
 Currently the delay and the OS makes things straightforward for you. But 
 TCP doesn't behave like you expect, and you are very likely to run into 
 trouble if the machine, the network, or the system starts taking 
 additional 
 load.

 You need to frame the data. A good way is to use 4 bytes as a size 
 (unsigned 32 bit integer), followed by a payload of that size. You can 
 then 
 avoid this becoming an uncontrolled explosion in your software at a later 
 date. You can also close connections early if too large messages get sent, 
 etc.



-- 
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/1b994fb3-5cda-46d3-a44c-218dc4cdf647n%40googlegroups.com.