VgaGames4

VgaGames4 - network man-pages

[.. upper level ..]

# vg4->nw->put_zdata()

Put additional-data to be sent along with input-events to the network-server.

SYNTAX
void vg4->nw->put_zdata(const struct VG_NwZdata *zdata)
FUNCTION PARAMETERS

zdata | Data to be sent

DESCRIPTION
Put additional-data to be sent along with input-events to the network-server. The element clnr of zdata needs not to be set. The network-server will re-send this data to all clients. The data can be retrieved with vg4->nw->update().
EXAMPLE

    /* send additional-data when space-key is pressed, print retrieved additional-data to stdout */

    struct VG_NwZdata nw_zdata;
    VG_BOOL dowait;
    int clnr;
    int key_zdata;

    /* set space-key as local key to send additional-data */
    if ((key_zdata = vg4->input->key_insert("Send additional-data", VG_FALSE, VG_FALSE)) == 0) { VG_dest(); exit(1); }
    vg4->input->key_setkbd(key_zdata, VG_INPUT_KBDCODE_SPACE);

    /* clnr shall be client-number of local client */

    for (;;) {
      if (!vg4->nw->update(&dowait, &nw_zdata)) { VG_dest(); exit(1); }
      if (!vg4->nw->is_connected(clnr)) { VG_dest(); exit(0); }

      /* player pressed key to send additional-data? */
      if (vg4->input->key_newpressed(key_zdata)) {
        struct VG_NwZdata zdata_put;
        snprintf(zdata_put.data, sizeof(zdata_put.data), "Hello, i am client %d", clnr);
        zdata_put.size = strlen(zdata_put.data) + 1;  /* set string null-terminated */
        vg4->nw->put_zdata(&zdata_put);
      }

      /* check for additional-data in nw_zdata */
      if (nw_zdata.size > 0) {
        printf("From client %d: %s\n", nw_zdata.clnr, nw_zdata.data);  /* data is null-terminated */
      }

      if (dowait) { vg4->misc->wait_time(50); }
    }

SEE ALSO
vg4->nw->update()