write and read method in TCP stream