add thread and socket function