Exemple #1
0
/* Send a message to a client telling them that a friend has logged on/off */
void client_send_friendmsg(ship_client_t *c, int on, const char *fname,
                           const char *ship, uint32_t block, const char *nick) {
    if(fname[0] != '\t') {
        send_txt(c, "%s%s %s\n%s %s\n%s BLOCK%02d",
                 on ? __(c, "\tE\tC2") : __(c, "\tE\tC4"), nick,
                 on ? __(c, "online") : __(c, "offline"), __(c, "Character:"),
                 fname, ship, (int)block);
    }
    else {
        send_txt(c, "%s%s %s\n%s %s\n%s BLOCK%02d",
                 on ? __(c, "\tE\tC2") : __(c, "\tE\tC4"), nick,
                 on ? __(c, "online") : __(c, "offline"), __(c, "Character:"),
                 fname + 2, ship, (int)block);
    }
}
Exemple #2
0
void *handler(void *param)
{
  data_t *data = param;
  printf("received: %s\n", data->buf);
  send_txt(data->sock, &(data->incoming_addr), "welcome!");
  free(data);
  return NULL;
}
Exemple #3
0
int main(int argc, char **argv)
{
  int sock;
  char *hostname;
  struct hostent *hostinfo;
  struct sockaddr_in addr;

  if (argc < 2)
  {
    printf("usage: cli hostaddr\n");
    exit(1);
  }

  hostname = argv[1];

  /* create socket */
  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock < 0) err("socket()");

  /* get IP */
  hostinfo = gethostbyname(hostname);
  if (hostinfo == NULL) err("gethostbyname");

  /* prepare inet address */
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(SRV_PORT);
  addr.sin_addr = *(struct in_addr *) hostinfo->h_addr;

  /* make TCP connection */
  printf("connecting to %s:%i\n", inet_ntoa(addr.sin_addr), SRV_PORT);
  if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) err("connect");

  if (!send_txt(sock, "hello!"))
  {
    close(sock);
    err("send hello");
  }

  if (!recv_txt(sock))
  {
    close(sock);
    err("recv greetings");
  }

  close(sock);
  return 0;
}