(十)嵌入式:使用TCP协议实现图传

本文介绍了一个通信项目中使用TCP协议进行无线图传的实践,详细阐述了服务器端和客户端的代码实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这段时间做了通信相关的项目,需要用到无线图传,因此想到了用TCP协议实现。废话不多说,直接上代码:
服务器端:


#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <sys/socket.h>
                                  
#define PORT 5000                      // The port which is communicate with server
#define BACKLOG 10
#define LENGTH 16384                     // Buffer length                                                                                 
int main ()
{   int sockfd;                        // Socket file descriptor
    int nsockfd;                       // New Socket file descriptor
    int num;
    int sin_size;                      // to store struct size
    char sdbuf[LENGTH];                // Send buffer
    struct sockaddr_in addr_local;     
    struct sockaddr_in addr_remote;    
    FILE *fp;
               
    /* Get the Socket file descriptor */  
    if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 )  
    {   
        printf ("ERROR: Cannot obtain Socket Despcritor\n");
        return (0);
    }
    else
    {
        printf ("OK: Obtain Socket Despcritor sucessfully\n");
    }
    
    /* Fill the local socket address struct */
    addr_local.sin_family = AF_INET;           // Protocol Family
    addr_local.sin_port = htons(PORT);         // Port number
    ad
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值