From my own experience, I found that it is very important to develop a network of contacts while you are working on your own projects, and not leave it to the very last moment. This means to actively meet other people at every chance you have, openly share your ideas, and expose yourself to other people ideas. So take every opportunity to meet visiting professors, postdocs, and other students.
I found that attending and actively participating at conferences is the most efficient way to develop a personal network of contacts. However, this requires quite a bit of effort, as besides of delivering your own talk you need to effectively interact with lots of people (this is different from just having a casual conversations and can be quite exhausting if you do this non-stop for a whole week). Going for the after-conference dinner and drinks is probably one of the most important parts.
I think that socialising at conferences is one of the most fun and effective ways to meet future collaborators and even land a job (in the long term).