[go-nuts] Implementing a custom TCP client

2017-09-20 Thread Tamás Gulácsi
I don't see anything obviously wrong, but using length-prefixed messages would 
simplify reading (no need to buffer) and wouldn't complicate writing.
My 2¢

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Implementing a custom TCP client

2017-09-20 Thread newbgopher
Hi all!
I already asked this on reddit 
,
 
but I figured might as well ask it here.
Im trying to implement a custom TCP client. This protocol allows request 
from both the client and the server


Scenario 1:

Client ---REQUEST--> Server

Client <-RESPONSE--- Server


Scenario 2:

Client <--REQUEST Server

Client ---RESPONSE--> Server


Here's 

 simplified 
form of the client. This approach uses a goroutine to read the *net.Conn, 
*parse 
the string to determine the type, 
and send the string to the appropriate channel for that type. Typical usage 
of this client is as follows

c := client.New("localhost:")
c.Connect()
c.Send("message")

On small workloads, it works fine, however calling Send around 100 times a 
second times out. 
I can confirm using wireshark that the server indeed sent a response, 
however it seems like the readLoop wasn't able read it and send it to the 
channel.
I would like to ask if this approach is reasonable. Id like to ask anyone 
out there have implemented a client golang library thats able to both send 
and receive requests from  the server. Basically a bidirectional tcp 
client. I know *nats *is similar to this, however their protocol parsing is 
too complex for me. Any new approach/advise will be nice. 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.