How to append all new messages in a slice?

69 views
Skip to first unread message

nks

unread,
Jan 14, 2020, 10:03:08 PM1/14/20
to golang-nuts
Hello Gophers,

I created a TCP server that gets all the requests from the client and replies, however, when I try to append those requests in a slice, the next request erases the previous one.

The server should get requests and continuously save them in a slice for future manipulation.



please help me to fix it...


Kurtis Rader

unread,
Jan 14, 2020, 10:16:40 PM1/14/20
to nks, golang-nuts
Line 55 creates a new slice1 object every time you execute the body of the loop. So it's always empty when you do the append(slice1, dataT). Try moving it to line 37. I didn't closely examine your code but it looks like there are other problems with it. For example, you don't use slice2 and the logic for assigning to it looks wrong. 

--
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/9211b53e-d3b2-4fdb-81a3-84bb757a585f%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages