贴代码贴了好几次都不成功,直接给出源码路径吧,发送接收都在里边
https://download.csdn.net/download/chnim/10505101
加QQ群一起交流学习音视频开发:476513431
经过思考觉得上次写的那个虽然没有问题但是还是有点不妥,做了一下的修改
1.现在发送端发送文件只需要将路径传给发送端,发送库去读文件发送
2.接収时,只需要指定个存放路径文件会自动写到指定路径,上次写的那个需要自己读文件推送buffer
发送端和接收端都是C++库,可以集成到一起
公共函数只有头文件
#ifndef _SYS_FUN_H__
#define _SYS_FUN_H__
#ifdef WIN32
#include <windows.h>
#else
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <pthread.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <syslog.h>
#include <dirent.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#endif
#include <pthread.h>
//#define WIN32
#ifdef WIN32
#define nsleep Sleep
#else
#define nsleep usleep
#endif
#define MAX_PACKET 50*1024*1024
#define TCP_MAX_PACK 135000
class CThreadLock
{
public:
CThreadLock() { pthread_mutex_init(&m_lock, NULL); }
~CThreadLock() { pthread_mutex_destroy(&m_lock); }
public:
void Lock() { pthread_mutex_lock(&m_lock); }
void UnLock() { pthread_mutex_unlock(&m_lock); }
private:
pthread_mutex_t m_lock;
};
#endif
发送端多路控制类,外部可调用的接口,头文件
/*
MultiNetUtil.h create by long
MultiNetUtil interface
*/
#ifndef _MULTI_NET_UTIL_H__
#define _MULTI_NET_UTIL_H__
#include <iostream>
#include <vector>
#include <map>
#include "sysfun.h"
#define MAX_BUFFER 65535
#define PACKSIZE 65000
#ifdef WIN32
#define OUT_CLASS
#ifdef OUT_CLASS
#define OUT_EX_CLASS _declspec(dllexport)
#else
#define OUT_EX_CLASS _declspec(dllimport)
#endif
#endif
class UDPNetShare;
class TCPNetShare;
typedef struct _CIPInfo {
std::string strIP;
int nPort;
int nChannel;
_CIPInfo()
{
strIP = "";
nPort = 5000;
nChannel = 0;
}
}CIPPort;
/*
Server ----->client
*/
// size
typedef struct _NetData {
int nIndex;
int nBufSize;
bool bFinish;
char buffer[PACKSIZE];
int nTotalSize;
}NetData;
typedef struct _DataInfo{
int nChannel;
unsigned char* pBuf;
int nSize;
}DataInfo;
//file info
typedef struct _FileInfo{
int nChannel;
std::string strFilePath;
}FileInfo;
//�ͻ������ֺͿͻ��˶�Ӧ�����·
typedef struct _TCPCleint
{
#ifdef WIN32
SOCKET sock;
#else
int sock;
#endif
int nChannel;
}TCPClient;
//�˿ںź�ip��ַ��Ӧ����һ·���
typedef struct _TCPChannel
{
std::string strIP; //�ͻ���IP
int nPort; //�ͻ��˶˿�
int nChannel; //�ͻ���ȡ��һ·��Ƶ
}TCPChannel;
#ifdef WIN32
class OUT_EX_CLASS MultiNetUtil
#else
class MultiNetUtil
#endif
{
public:
//���뱾�ذ