I am working on a multiplayer game and I want to connect players which are in the same network.I have to achieve this using digital Ocean as we do it in AWS security group
That would be Cloud Firewalls. In your droplet, you'll see the Firewall section in the Networking tab