Re: Multiple ports? Andrew Ritchie at "May 19, 99 07:44:35 pm"

From: Martijn Schoemaker (
Date: 05/19/99

> Is it possible to run a server (mud or otherwise) on two different ports at
> the same time without running two different instances? I'd like to run my
> MUD on port 8080 as well, which would probably allow most people who cannot
> conect to the game because of a firewall to access the game, as 8080 is
> normally used for http. I don't think many firewalls block /this/ port.
> Is it possible to bind to two different ports, and make the game listen on
> both ports, and handle both ports? This will be hard because I know one of
> the select() functions blocks until a user has connected to the game. I
> could probably take that blocking code out, and the game should run fine. In
> fact, I have done so and it does - you just don't get the "No connections.
> Going to sleep." message and the MUD keeps ticking over, which isn't such a
> bad thing.
> Any help would be appreciated,
> Andrew.

We had those problems on our mud (university closed port 4000 on their firewall)
and so I adapted Imagica to use up to 10 port (just a number I liked ;)) and
we are sucesfully running on port 4000 and 119 (with an external redirector,
cause binding to ports < 1024 needs root access) and it works like a charm.

It's not hard to implement just do the following :
in comm.c :

change in the prototype definitions :
void init_game(int port); to void init_game(int ports[]);
void game_loop(int mother_desc); to void game_loop(int mother_desc[]);

in init_game:
change init_game(port) to init_game(int ports[])
change int mother_desc; to int mother_descs[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; (for 10 ports)
remove the line with 'init_socket' and insert the following :
  for (i = 0;ports[i] != -1;i++)
        sprintf(buf, "- Opening port %d ...", ports[i]);
        mother_descs[i] = init_socket(ports[i]);
change game_loop(mother_desc); to game_loop(mother_descs);
remove the line with 'close(mother_desc);' and  insert the following:
  for (i = 0;mother_descs[i] != -1;i++)

in game_loop:
Now it gets tricky because my comm.c is heavily modified from the stock one.
(Imagica was origibally built from PL7) but I think you can get the general

I commented out the whole sleepcode to make the MOBs do stuff even when there
are no connections. If you want to keep the sleepcode in the you'll have to
adapt it to select over all motherdescs, take a look at the next code about how
to do that.

Delete everything from : /* Set up the ..... till /* At this point
Insert this code :
    /* Set up the input, output, and exception sets for select(). */

    maxdesc = -1;
    /* Add all our mother sockets */
    for (i = 0;mother_descs[i] != -1;i++)
        FD_SET(mother_descs[i], &input_set);
        if (mother_descs[i] > maxdesc)
                maxdesc = mother_descs[i];

    for (d = descriptor_list; d; d = d->next)
        if (d->descriptor > maxdesc)
                maxdesc = d->descriptor;
        FD_SET(d->descriptor, &input_set);
        FD_SET(d->descriptor, &output_set);
        FD_SET(d->descriptor, &exc_set);
Delete the two lines after : /* If there are new connections waiting, accept them. */
Insert the following :
    /* New connection waiting for us? */
    for (i = 0;mother_descs[i] != -1;i++)
        if (FD_ISSET(mother_descs[i], &input_set))
                new_descriptor(mother_descs[i], i);

in main():
change 'int port;' to 'ports[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};' (for 10 ports)
change 'port = DFLT_PORT;' to 'ports[0] = DFLT_PORT;'
add the following just before the 'if (chdir(dir)<0)' line:
  /* Handle the ports */
  if (pos < argc)
    if (!isdigit(*argv[pos]))
        fprintf(stderr, "Usage: %s [-c] [-m] [-q] [-r] [-s] [-d pathname]"
                        " [-u UID] [port #1 port#2 ... port #n]\n", argv[0]);
        i = 0;
        while ((pos < argc) && (i < 10))
                if (!(ports[i] = atoi(argv[pos])))
                        fprintf(stderr, "Illegal port number.\n");
change 'init_game(port);' to 'init_game(ports);'
Well that's it. I cannot guarantee it will work for you because (as I men-
tioned earlyer) ImagicaMUD was build from 3.0PL7 so there could be differen-
ces. This will give you a general idea about how to do it, and if there are
questions, please feel free to ask.

Good luck,
Martijn Schoemaker (Aragorn)

Try : 4000 or 119 and be amazed !
In days long gone, the captain used to go down with his ship.  Now that
Windows NT is running Navy warships, the ships go down all by themselves.

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 12/15/00 PST