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 <https://golang.org/pkg/bytes/#Buffer> or strings.Builder > <https://golang.org/pkg/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 <non3...@gmail.com> 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/0970a627-4743-4216-bca4-445b905046c0n%40googlegroups.com.