Search code examples
androidserversocket

Multiple socket severs using a single port number


Hey I'm working on two android apps that work together to connect people to cabs (a client side app for the user and another app for the drivers). I want to use socket connections and I want a single cab company to use a single port...thing is, a single cab company can have many cabs and I want all the cab-drivers to see a ride request when a person wants a cab. Is this possible to achieve (in terms of socket i/o)? if not is there a different, more appropriate approach?

Any help/guidance would be much appreciated...


Solution

  • Of course it is possible. The server can listen on a single port, and differentiate between cab connections and user connections based on how they identify themselves in their communications with the server. Then the server can keep a list of identified cab connections, so when a request arrives from an identified user connection, loop through the list of cab connections sending the request to each one. This kind of thing is not uncommon, and is fairly basic to implement.