- 论坛徽章:
- 0
|
RT- bool LsUdpSocket::connect(char* ip, uint16_t port)
- {
- if(is_connect_ == true)
- return true;
- if(strcmp(ip,"255.255.255.255") == 0)
- {
- const int opt = 1;
- int nb = 0;
- nb = setsockopt(fd_, SOL_SOCKET, SO_BROADCAST, (char *)&opt, sizeof(opt));
- if(nb == -1)
- return false;
- }
- struct sockaddr_in dest_addr;
- bzero(&dest_addr,sizeof(dest_addr));
- dest_addr.sin_family=AF_INET;
- dest_addr.sin_port=htons(port);
- dest_addr.sin_addr.s_addr=inet_addr(ip);
- if(::connect(fd_,(struct sockaddr *)&dest_addr, sizeof(dest_addr)))
- {
- return false;
- }
- is_connect_ = true;
- return true;
- }
复制代码 不能接受数据 |
|