change write function to send and add protocol negotiation in tpdu layer