網(wǎng)盤鏈接:https://pan.baidu.com/s/1TKdHdeuDI8XPaakepvSLZQ?pwd=1688?
提取碼:1688
利用UDP實(shí)現(xiàn)雙人不同機(jī)器聊天(服務(wù)器可以被多人連接,顯示多人聊天記錄)
//-------------------------服務(wù)器
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
int main(int argc,char *argv[])
{
? ? ? ? int sockfd = 0;
? ? ? ? struct sockaddr_in bindaddr;
? ? ? ? unsigned int port = 8000;
? ? ? ?
? ? ? ? if(argc > 1)
? ? ? ? {
? ? ? ? ? ? ? ? port = atoi(argv[1]);
? ? ? ? }
? ? ? ? sockfd = socket(AF_INET,SOCK_DGRAM,0);
? ? ? ? if(sockfd < 0)文章來源:http://www.zghlxwxcb.cn/news/detail-787391.html
? ? ? ? ? ? ? ? perror("socked&文章來源地址http://www.zghlxwxcb.cn/news/detail-787391.html
到了這里,關(guān)于嵌入式培訓(xùn)機(jī)構(gòu)四個(gè)月實(shí)訓(xùn)課程筆記(完整版)-Linux網(wǎng)絡(luò)編程第三天-UDP編程練習(xí)題(物聯(lián)技術(shù)666)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!