Im writing a program that uses sockets for inter process communication however i have come to a road block and cant get my code to compile. i have googled all the errors with no luck finding a solution. If any one can help me it would be appreciated. Here is a more detailed description of the assignment http://voyager.cs.bgsu.edu/gzimmer/cs3270/cs3270fa11lab4.pdf
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <iostream.h>
int main(int argc,char *argv[])
{
int sv[2]; /* the pair of socket descriptors */
char buf[256]; /* for data exchange between processes */
int m, n, random;
bool loop = true;
char check[50];
m = atoi(argv[1]);
n= atoi(argv[2]);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
perror("socketpair");
exit(1);
}
if (!fork()) { /* childm */
while(loop){
read(sv[0], &buf, 256);
random = atoi(buf);
if(random % 2 == 0)
{
check = "even";
}
else{
check = "odd";}
if(random > 0){
if(n>0){
cout << "Recieved " << random << " from p0 it is "<< check << endl;
random = rand() % 1000;
buf = itoa(random, buf, 10);
cout << "Sending " << random << "to p0" << endl;
write(sv[1], &buf, 256);
n--;
}
else{
cout << "Recieved " << random << " from p0 it is "<< check << endl;
buf = itoa(0, buf,10);
write(sv[1], &buf, 256);
}
}
else if(random == 0){
if(n>0){
random = rand() % 1000;
buf = itoa(random, buf, 10);
cout << "Sending " << random << "to p0" << endl;
write(sv[1], &buf, 256);
n--;
}
else{
buf = itoa(-1, buf,10);
write(sv[1], &buf, 256);
}
}
else if( random == -1){
loop = false;
buf = itoa(-1, buf,10);
write(sv[1], &buf, 256);
}
}
cout << "P1 is now finished"<< endl;
} else { /* parent n*/
if(n>0){
random = rand() % 1000;
buf = itoa(random, buf, 10);
cout << "Sending " << random << "to p1" << endl;
write(sv[0], &buf, 1);
n--;
}
else{
buf = itoa(0, buf,10);
write(sv[0], &buf, 1);
}
while(loop){
read(sv[0], &buf, 1);
random = atoi(buf);
if(random % 2 == 0)
{
check = "even";
}
else{
check = "odd";}
if(random > 0){
if(n>0){
cout << "Recieved " << random << " from p1 it is "<< check << endl;
random = rand() % 1000;
buf = itoa(random, buf, 10);
cout << "Sending " << random << "to p1" << endl;
write(sv[0], &buf, 1);
n--;
}
else{
cout << "Recieved " << random << " from p1 it is "<< check << endl;
buf = itoa(0, buf,10);
write(sv[0], &buf, 1);
}
}
else if(random == 0){
if(n>0){
random = rand() % 1000;
buf = itoa(random, buf, 10);
cout << "Sending " << random << "to p1" << endl;
write(sv[0], &buf, 1);
n--;
}
else{
buf = itoa(-1, buf,10);
write(sv[0], &buf, 1);
}
}
else if( random == -1){
loop = false;
buf = itoa(-1, buf,10);
write(sv[0], &buf, 1);
}
}
cout << "PO is now finished"<< endl;
}
return 0;
}