请教TCP、UDP开发问题

tongjing524 tongjing524 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
linux 与本机Qt 之间 UDP网络通信,双方不能连接?(附部分代码)

Qt部分:
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);

receiver = new QUdpSocket(this);
receiver->bind(QHostAddress("192.168.1.236"), 8800);
connect(receiver,SIGNAL(readyRead()),this,SLOT(showPicture()));
}
void Widget::showPicture()
{
qDebug("ret = %d\n", ret);
while(receiver->hasPendingDatagrams())
{
......
}
}


linux部分:
int sockfd;
struct sockaddr_in addr;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
bzero(&addr,sizeof(struct sockaddr_in));
addr.sin_family=AF_INET;
inet_aton("192.168.1.231", &addr.sin_addr);
addr.sin_port=htons(8800);
if(bind(sockfd,(struct sockaddr *)&addr,sizeof(struct sockaddr))==-1 )
{
printf("Bind lost:%s\n",strerror(errno));
exit(1);
}
while(1)
{
read(sockfd,buf,10);
}
...全文
评论 6
收藏 已收藏
分享
返回顶部
tongjing524
模式及实现 5,529 成员 4,167 内容