There are lots of different ways you can communicate between two instances of the same program. One of them, a network connection, being one of the most used ones.

You can have a client and a server in the same program without any problem. You should try to create some basic flowchart or diagram or whatever to find out how you can implement this. There are different ways to do this. Each with advantages and disadvantages.