generic socket event handling

resolves #43