Create single connection for entire application

Hi, I have two screens, First screen display Chats related to users, Second screen displays chat history of a particular person, So am using socket communication for fetching data. So I have created socket connection in the first component, am unable to use same socket in second component, how to solve please help me.

Components should not be doing networking stuff. Move all that into a service provider.

How to do that, I am beginner, soo please help me.