IP phone日志1

个人想做一个Linux下的IP phone,找了一些SIP资料,发现这协议够大,看osip项目都做了一两年,我也觉得难度太高,但想想难度高才有挑战嘛,自我安慰,呵呵.
第一步我想开始熟悉linux下的进程通讯, 预想有socket, pipe,queue,sigaction等要先掌握.
先不做服务器, 以两个客户程序User  Agent通信为主.
划分几个模块:
 1.Socket处理模块
 2.信令解析模块
 3.命令处理
 4.UI
 5.维护模块
 6.其它模块
 1与2之间采用queue通讯.socket以UDP为基础.
 写了两个udp通讯的客户与服务程序:
 服务程序: bigdogsrv.c
***********************************************
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define MYPORT 4950 /* the port users will be sending to */
#define MAXBUFLEN 100

main()
{
  int sockfd;
  struct sockaddr_in my_addr; /* my address information */
  struct sockaddr_in their_addr; /* connector's address information */
  int addr_len, numbytes;
  char buf[MAXBUFLEN];
  // memset(buf,"",MAXBUFLEN-1);
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  my_addr.sin_family = AF_INET; /* host byte order */
  my_addr.sin_port = htons(MYPORT); /* short, network byte order */
  my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */
  bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */
  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) /
      == -1) {
    perror("bind");
    exit(1);
  }
  addr_len = sizeof(struct sockaddr);
  while(strncmp(buf,"bye",3)!=0){//接到bye 就结束
    if ((numbytes=recvfrom(sockfd, buf, MAXBUFLEN, 0, /
                           (struct sockaddr *)&their_addr, &addr_len)) == -1) {
      perror("recvfrom");
      exit(1);
    }
    printf("got packet from %s/n",inet_ntoa(their_addr. sin_addr));
    printf("packet is %d bytes long/n",numbytes);
    buf[numbytes] = '/0';
    printf("packet contains /"%s/"/n",buf);
  }

  close(sockfd ) ;
}
********************************

客户端: bigdogclient.c
***************************************
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define MYPORT 4950 /* the port users will be sending to */

int main(int argc, char *argv[])
{
  int sockfd;
  struct sockaddr_in their_addr; /* connector's address information */
  struct hostent *he;
  int numbytes;
  if (argc != 3) {
    fprintf(stderr,"usage: talker hostname message/n");
    exit(1);
  }
  if ((he=gethostbyname(argv[1])) == NULL) { /* get the host info */
    herror("gethostbyname");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  their_addr.sin_family = AF_INET; /* host byte order */
  their_addr.sin_port = htons(MYPORT); /* short, network byte order */
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  bzero(&(their_addr.sin_zero), 8); /* zero the rest of the struct */
  if ((numbytes=sendto(sockfd, argv[2], strlen(argv[2]), 0, /
                       (struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) {
    perror("sendto") ;
    exit(1);
  }
  printf("sent %d bytes to %s/n",numbytes,inet_ntoa(their_addr.sin_addr));
  close(sockfd);

  return 0;
}
************************************

makefile:写的简单了
**************************
CC=gcc

srv:bigdogsrv.o
        $(CC) -o srv bigdogsrv.o
bigdogsrv.o:bigdogsrv.c
        $(CC)  -c -g bigdogsrv.c

 

client:bigdogclient.o
        $(CC) -o client bigdogclient.o
bigdogclient.o:bigdogclient.c
        $(CC) -c -g bigdogclient.c

clean:
        rm -f *.o
        rm -f srv
        rm -f client

**************************************
make
make client
然后先运行srv, 再运行client 192.168.1.168 love you

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
优化以下代码public function convertedAndSameActiveClue(&$postData, $clueState, $handleSource = Constant::REGISTER) { $result = $this->result; $recentCluePhones = DistributeCommon::getRecentIpClue($postData['phone'], $postData['active_ip']); $specified_channel = TSalesConf::getValue('filter_specified_channel_categories'); foreach ($recentCluePhones as $recentCluePhone) { //过滤指定渠道大类 if ($specified_channel) { $specified_channel = json_decode($specified_channel, true); if (in_array($postData['channel_big_type'], $specified_channel, true)) { event(new SaveOperateLogEvent(OperateLog::OPERATING_CLUE, $postData['phone'] . '已转化线索同IP不下发,过滤指定渠道大类' . json_encode($postData))); break; } } $stateInfo = app(Clue::class)->getClue($recentCluePhone, '+86');//查找当前线索的状态 //排除代理商线索 if ($stateInfo['transform'] && $stateInfo['info']['base_id'] != self::AGENT_BASE_ID) { $result[self::IS_NEXT_CLUE] = true; $result[self::IS_TRIGGER_RULE] = true; $result[self::IS_DISTRIBUTE] = false; $result[self::BASE_ID] = self::WAIT_ACTIVE_BASE_ID; $result[self::POOL_ID] = self::WAIT_ACTIVE_POOL_ID; event(new SaveOperateLogEvent(OperateLog::OPERATING_CLUE, $postData['phone'].' 已转化线索同IP不下发, 与'.$recentCluePhone.'同一IP')); return $result; } } if (!empty($recentCluePhones)) { Log::channel('distribute')->info($postData['phone'] . ' 存在同一IP ' . json_encode($recentCluePhones) . ', 但该线索未转化或不存在与新系统中,或是代理商线索,或过滤指定渠道大类'); event(new SaveOperateLogEvent(OperateLog::OPERATING_CLUE, $postData['phone'] . ' 存在同一IP ' . json_encode($recentCluePhones) . ', 但该线索未转化或不存在与新系统中,或是代理商线索,或过滤指定渠道大类')); } return $result; }
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值