For Loop vs Event-Driven

Joshua Rodrigues

Greenhorn

Posts: 25

posted 3 years ago

Hi. I have two questions:
1. I read somewhere that instead of looping through every player (below), you use could Events to do it for you:

I'm not sure as to how to use Events in place of a for loop. I've been thinking on this for days, but I'm still stuck. Would anybody be so kind as to give me an example of using an Event instead of a for loop?
2. Is there any way to accept multiple connections on a server without using a while loop? Maybe use Events to handle the acceptance of connections?

1) Well, basically, if you write Player so that when it moves it issues an event, you would then listen for that event instead of using a for loop, which will waste cycles.

2) I'm not a server expert, but I think one way to except multiple connections is to have one port that listens for connection requests, then once it gets one, it forks a process (or starts a Thread) that uses some random port. This port is sent back to the client which disconnects from the listening port and reconnects to the new port and process.