Allow writes only when socket is in connected state

Change-Id: I3e265ccba334301444611a8013568ba52cca5bcd
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>