⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcast-srv.c

📁 一个C编写网络广播的程序
💻 C
字号:
/* mcast-srv.c -- multicasting server main thread  *   * This file is part of 'netcast' program, released under BSD License.  * (c) 2001-2002 Stanis砤w Pa秌o <staszek@nutki.com>. All rights reserved.    */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <pthread.h>#include <signal.h>#include "mdist.h"#include "mcast.h"#include "util.h"#include "server.h"void *mcast_srv_main(void *args) {  struct sockaddr_in sin;                         /* endpoint address */  int ms,i;                                       /* multicast socket */  struct sempack *msp;                            /* Sync with TCP */  char adr[128];  long long total=0;  int start,now;  float speed;    /* Open some random multicast group */  msp = (struct sempack *) args;     srand(time(0));  sprintf(adr,"%s%d",MCAST_ADDR_BASE,rand()%254+1);  sin = make_addr(adr,server_port);  mdini.group = sin;  ms = init_mcast_socket(&sin);   md_init();    /* Let TCP servers accept connections */  V(msp->init);  P(msp->accept);  MSG(7,"All your bases are belong to us.");  start=time(0);  do {         /* Read data from stdin */    i = md_fill(0);    if (!client_count) {      i=0; mdhead.pkt=0;    }    MSG(7,"Lower your shields and surrender your ships.");    /* tcp: Send headers */    V(msp->prepare);    P(msp->ready);    /* multicast data */    while (i--)       sendto(ms,mdbuf[i],mdbuf[i]->siz+sizeof(struct mdmsg),0,(struct sockaddr *)&sin,sizeof(sin));    MSG(7,"Your biological distinctiveness will serve us.");    /* tcp: Send end-of-data marks */    V(msp->prepare);    P(msp->finish);    now=time(0);    total=total+mdhead.siz;    speed=(((float)total)/(1024*1024))/((float) now-start);    fprintf(stderr,"\rnetcast: sent %lld bytes in %d secs at %.3f MBps",                    total,now-start,speed);                     } while (mdhead.pkt);   /* fin. */  MSG(7,"Resistance is futile. You shall be assimilated.");  fprintf(stderr,"\nnetcast: done.\n");  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -