why my cd data transmision pgm is not functioning when it runs with cd eject program?
hai,
i am transmitting cd data from client to server and transmission is done. then i added some control transmission,if server sends '1', client ejects cd and then manually closed by user. then my cd data transmission performed. both program are not working parallely. please help me. here i am attaching client part.
client program
#include <iostream>
#include <fstream>
#include <string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <unistd.h>
using namespace std;
int main(int argc, char *argv[])
{
printf("This is the client program\n");
int sockfd;
int len;
ssize_t nm;
struct sockaddr_in address;
int result;
//Create socket for client.
sockfd = socket(AF_INET, SOCK_STREAM, 0);
//Name the socket as agreed with server.
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("172.16.100.57");
address.sin_port = htons(4010);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
printf("client connected");
if(result == -1)
{
perror("Error has occurred");
exit(0);
}
if (sockfd > 0)
{
char buf[1024];
int ch,l=0;
int bufsize=1024; /* a 1K buffer */
printf("i am in center\n");
/*void *buffer=malloc(bufsize);*/
cout<<"The Client "<<inet_ntoa(address.sin_addr)<<" is
Connected...\n";//inet_ntoa(address.sin_addr));
nm=recv(sockfd,buf,sizeof(buf),0);
printf("cd inserted");
usleep(90000);
if((strcmp(buf,"1")==0))
{
printf("cd inserted");
usleep(10000);
int fd = open("/dev/sr0", O_RDONLY);
// Eject the CD-ROM drive
ioctl(fd, CDROMEJECT);
printf("cd inserted");
close(fd);
}
usleep(9000);usleep(9000);
FILE *fp;
fp=fopen("/dev/sr0","rb");
char buffer[1024];
int bytes;
bytes=1;
while(bytes!=0)
{
bytes=fread(buffer, sizeof(buffer), 1, fp);
cout<<"\nSIZE"<<bytes;
usleep(900000);
printf("msg from %s:%d (%d bytes)\n",
inet_ntoa(address.sin_addr),ntohs(address.sin_port),bytes);
cout<<buffer;
send(sockfd,buffer,sizeof(buffer),0);
usleep(1000);
}
fclose(fp);
}
else
{
cout<<"Client not connected ...\n";
}
close(sockfd);
exit(0);
}
Last edited by neethu; 03-15-2012 at 12:06 PM.
|