LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2012, 11:23 AM   #1
neethu
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 03-15-2012, 11:33 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Could you please edit your post and place the code within CODE tags so that it preserves the original formatting. As it is right now, it is very difficult to read.

Also, please choose as to whether you plan to develop in C or in C++. Please avoid doing both!
 
  


Reply

Tags
c++, ioctl, linux, netwoking



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Transmision doesn't download asliyanage Linux - Desktop 2 02-09-2010 03:35 AM
Error Message: Program eject is using a deprecated SCSI ioctl, please convert to SG Jogie Linux - Newbie 4 08-24-2009 06:35 PM
Program in C to convert a PGM file into PBM singh.vikas85 Programming 1 06-12-2009 07:15 AM
anybody knows a good data recovery program that runs on linux? anon104 Linux - Software 4 06-04-2007 03:08 PM
Program to eject cdrom drive ... doubt tuxfood Programming 3 07-20-2005 03:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration