#include <iostream>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <arpa/inet.h>
using namespace std;
int main (int argc, char *argv[])
{
cout << "Hello world! 5" << endl;
int localSocket,remoteSocket;
struct sockaddr_in localAddr,remoteAddr;
localSocket = socket(AF_INET, SOCK_DGRAM, 0);
bzero(&localAddr, sizeof(localAddr));
localAddr.sin_family = AF_INET;
localAddr.sin_port = htons(7777);
//localAddr.sin_addr.s_addr = INADDR_ANY;
localAddr.sin_addr.s_addr = inet_addr("192.168.1.40");
cout << "socket returned : " << localSocket << endl;
int result = bind(localSocket, (struct sockaddr *)&localAddr, sizeof(localAddr));
cout << "bind returned : " << result << endl;
FILE *pFile_;
pFile_ = fopen("test.264", "r+");
if(!pFile_)
{
cout << "fopen error " << pFile_ << endl;
}
char buffer[1024];
int i = 0;
while(1)
{
//memset(buffer, 0 , 1024);
socklen_t remoteAddrLength = sizeof(remoteAddr);
//result = recvfrom(localSocket, &buffer, sizeof(buffer), 0, (struct sockaddr *)&remoteAddr, &remoteAddrLength);
//fwrite(buffer, 1024, 1, pFile_);
//printf("received UDP %d, result %d \n", i++, result);
//构建一个char[]缓冲区,包含要发送的数据,在这里可以自己定义要发送的数据。
char sendBuff[512];
memset(sendBuff, 0, sizeof(sendBuff));
int fFrameSize = fread(sendBuff, 1, sizeof(sendBuff), pFile_);
printf("fFrameSize %d, %d \n", fFrameSize, sizeof(sendBuff));
if (fFrameSize != sizeof(sendBuff))
{
fseek(pFile_, 0L, SEEK_SET);
//printf("fFrameSize %d, %d \n", fFrameSize, sizeof(sendBuff));
//assert(false);
}
int nSend = sendto(localSocket, &sendBuff, fFrameSize,0, (struct sockaddr *)&localAddr,remoteAddrLength);
printf("i %d nSend %d \n", i++, nSend);
usleep(2000);
}
fclose(pFile_);
fflush(pFile_);
}
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <arpa/inet.h>
using namespace std;
int main (int argc, char *argv[])
{
cout << "Hello world! 5" << endl;
int localSocket,remoteSocket;
struct sockaddr_in localAddr,remoteAddr;
localSocket = socket(AF_INET, SOCK_DGRAM, 0);
bzero(&localAddr, sizeof(localAddr));
localAddr.sin_family = AF_INET;
localAddr.sin_port = htons(7777);
//localAddr.sin_addr.s_addr = INADDR_ANY;
localAddr.sin_addr.s_addr = inet_addr("192.168.1.40");
cout << "socket returned : " << localSocket << endl;
int result = bind(localSocket, (struct sockaddr *)&localAddr, sizeof(localAddr));
cout << "bind returned : " << result << endl;
FILE *pFile_;
pFile_ = fopen("test.264", "r+");
if(!pFile_)
{
cout << "fopen error " << pFile_ << endl;
}
char buffer[1024];
int i = 0;
while(1)
{
//memset(buffer, 0 , 1024);
socklen_t remoteAddrLength = sizeof(remoteAddr);
//result = recvfrom(localSocket, &buffer, sizeof(buffer), 0, (struct sockaddr *)&remoteAddr, &remoteAddrLength);
//fwrite(buffer, 1024, 1, pFile_);
//printf("received UDP %d, result %d \n", i++, result);
//构建一个char[]缓冲区,包含要发送的数据,在这里可以自己定义要发送的数据。
char sendBuff[512];
memset(sendBuff, 0, sizeof(sendBuff));
int fFrameSize = fread(sendBuff, 1, sizeof(sendBuff), pFile_);
printf("fFrameSize %d, %d \n", fFrameSize, sizeof(sendBuff));
if (fFrameSize != sizeof(sendBuff))
{
fseek(pFile_, 0L, SEEK_SET);
//printf("fFrameSize %d, %d \n", fFrameSize, sizeof(sendBuff));
//assert(false);
}
int nSend = sendto(localSocket, &sendBuff, fFrameSize,0, (struct sockaddr *)&localAddr,remoteAddrLength);
printf("i %d nSend %d \n", i++, nSend);
usleep(2000);
}
fclose(pFile_);
fflush(pFile_);
}