Executing scripts on different devices of the same machine

I want to run an interactive session(Chat between 2 devices) by registering different ports of the same machine.Is it possible to interact with all the devices connected to the same machine. I’m automating a hybrid App. I’m facing issues in switching between the drivers.It says session not found.