tidying up socket sending and triggering dom events on succesful socket reception