• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: SO_NOSIGPIPE option.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SO_NOSIGPIPE option.


  • Subject: Re: SO_NOSIGPIPE option.
  • From: Robert Bell <email@hidden>
  • Date: Wed, 07 Oct 2009 13:55:20 -0700


The client.

#include <iostream>
#include <string>

//Network includes.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

// Other includes.
#include <sys/time.h>

#define PORT 9500

int main(int argc, char**args){


int socket = -1;
struct sockaddr_in servaddr;
char *serverAddress = "127.0.0.1";


socket = ::socket(AF_INET, SOCK_STREAM, 0);
if(socket == -1){
std::cout << "error: unable to create socket" << std::endl;
exit(-1);
}


bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);


inet_pton(AF_INET, serverAddress, &(servaddr.sin_addr));


// Connect ...
if(connect(socket,(const struct sockaddr *)&servaddr,sizeof(struct sockaddr_in)) == 0){


FILE *fin = fdopen(socket, "r");
FILE *fout = fdopen(socket, "w");


bool connectionError = false;


int sizeOfData = 1024;
size_t nObj = 1;


const char *outData = "(sendCommand cmd_ListenToAmp 0 0 0)\n";
int sizeOfString = strlen(outData);


int count = 0;
while(true){


int inData[sizeOfData];
if(fread(reinterpret_cast<char *>(inData), sizeOfData * sizeof(int), nObj,fin) == nObj){
std::cout << "inData count: " << inData[0] << std::endl; 
}
else{
connectionError = true;
std::cout << "client: error: read fail" << std::endl;
}


if(connectionError){
exit(0);
}


count++;
sleep(1);
}
}
else{
std::cout << "client: error: failed to connect" << std::endl;
exit(-1);
}


exit(0);
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: SO_NOSIGPIPE option.
      • From: Vincent Lubet <email@hidden>
References: 
 >SO_NOSIGPIPE option. (From: Robert Bell <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Vincent Lubet <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Robert Bell <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: SO_NOSIGPIPE option.
  • Next by Date: Re: SO_NOSIGPIPE option.
  • Previous by thread: Re: SO_NOSIGPIPE option.
  • Next by thread: Re: SO_NOSIGPIPE option.
  • Index(es):
    • Date
    • Thread