My project is to send real time data captured by radar to the client. The data is saved in a .txt file which may contain both characters and integers. I have added the following code for file open and read on SERVER side.
char sendbuf;
char recvbuf = "";
fp = fopen("/mnt/host/test.txt", "r");
if(fp==NULL)
{
printf("cannot open file\n");
}
else
{
fgets(sendbuf,199,fp);
}
bytes_sent = send(sockfd, sendbuf, strlen(sendbuf), 0);
if((bytes_sent = send(acceptsocket,sendbuf,strlen(sendbuf),0)) < 0)
{
printf("SERVER : send failed.\n");
}
else
{
printf("SERVER : Send is OK \n");
printf("SERVER : Bytes sent:%ld.\n",bytes_sent);
}
if((bytes_recv=recv(acceptsocket,recvbuf,200,0))<0)
{
printf("SERVER : receive failed.\n");
}
else
{
printf("SERVER: recv() is OK.\n");
printf("SERVER: Received data is: \"%s\"\n", recvbuf);
printf("SERVER: Bytes received: %ld.\n", bytes_recv);
}
fclose(fp);
for CLIENT side the received string will be saved in the receive buffer before it is written in to another file:
FILE *fp;
fp = fopen ("c:\\test1.txt","w");
if(fp==NULL)
{
printf("cannot open file\n");
}
else
{
fputs(recvbuf,fp);
}
fclose(fp);
The file read and write code works fine when i run both server and client on VC++. But when i run the server on NIOS II board it doesnt do anything after
Socket created
Bind is OK
Listen is OK
accepted connection request
sometimes it just writes some junk data to a file. I dont know what the problem is. Is there any problem in my code NIOS can not read the file. I have placed the .txt file in the folder which have my c code for server according to Host file system. I have enabled the
altera_hostfs in the BSP editor. Please assist.