unsigned char EncBoardIP[4];
typedef struct
{
int Socket;
int DecPort;
int EncPort;
char *DecIp;
char *EncIp;
}SockStruct;
void InitNet(char * EncIP,char * DecIP)
{
unsigned long LIP;
unsigned char * BoardIP ;
LIP = inet_addr(EncIP);
BoardIP = (unsigned char*) &LIP;
EncBoardIP[0] = BoardIP[0];
EncBoardIP[1] = BoardIP[1];
EncBoardIP[2] = BoardIP[2];
EncBoardIP[3] = BoardIP[3];
SockConnect.EncIp = EncIP;
SockConnect.DecIp = DecIP;
SockConnect.EncPort = 10000;
SockConnect.DecPort = 20000;
CreateSocket(&SockConnect);
}
int CreateSocket(SockStruct *sockfd_all)
{
struct sockaddr_in ser_addr,cli_addr;
if((sockfd_all->Socket= socket(AF_INET,SOCK_DGRAM,0)) == -1)
{
perror("socket");
exit(-1);
}
bzero(&ser_addr,sizeof(ser_addr));
ser_addr.sin_family = AF_INET;
ser_addr.sin_addr.s_addr = inet_addr((sockfd_all->DecIp));
ser_addr.sin_port = htons(sockfd_all->DecPort);
bzero(&cli_addr,sizeof(cli_addr));
cli_addr.sin_family = AF_INET;
cli_addr.sin_addr.s_addr = inet_addr((sockfd_all->EncIp));
cli_addr.sin_port = htons(sockfd_all->EncPort);
if((bind(sockfd_all->Socket,(struct sockaddr *)&cli_addr,sizeof(cli_addr))) == -1)
{
perror("bind");
exit(-1);
}
if((connect(sockfd_all->Socket,(struct sockaddr *)&ser_addr,sizeof(ser_addr))) == -1)
{
perror("connect");
exit(-1);
}
return 0;
}
void* RecvThread(void* arg)
{
while(Flag)
{
if(RecvBufferFullOrEmpty()!=1) //判断缓冲区是否满
{
}
}
}
int main(int argc, const char *argv[])
{}
编译方法:
gcc -c videoplay.c
ar rcs libvideoplay.a videoplay.o
gcc -o play main.c -static -L. -lvideoplay -lpthread