kodex
2005.06.09, 03:12 PM
Sorry to keep bothering you guys but im pretty lost without my books and code, and searching google hasnt yeilded and great results yet. Im getting a "exited due to signal 13 (SIGPIPE)" on send();, this is a new one too me since its the send after making a network connection =p.
Anyways code for connection to host
static void SendConnectionRequestToHost(char *ipAddrString)
{
struct sockaddr_in hostAddr;
//creates a connection socket (TCP/IP Streaming)
gConnectionToHost = socket(AF_INET, SOCK_STREAM, nil);
//setup addy info for our host
bzero(&hostAddr, sizeof(hostAddr)); //clear
hostAddr.sin_family = AF_INET; //network type internet
hostAddr.sin_port = htons(5500); //our port number
inet_pton(AF_INET, ipAddrString, &hostAddr.sin_addr);
//issue connection request
if (connect(gConnectionToHost, (struct sockaddr *)&hostAddr, sizeof(hostAddr))< 0)
{
printf("CANNOT CONNECT!\n");
}//failed host is not there
if(WriteNetData(gConnectionToHost, "Hello", 32) <=0)
{
printf("FAILED WRITE");
}
}
Send Data Code
int WriteNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; //ptr to buffer
int count, n;
n = count =0;
while(count< numBytes) //loop until we have sent all bytes
{
n = send(socket, bytes, numBytes - count, 0); //send..... CRASHES HERE
if(n>0)
{
count += n;
bytes += n;
}
else
if(n<0) //error
return(-1);
}
return(count);
}
Thanks in advance guys
Anyways code for connection to host
static void SendConnectionRequestToHost(char *ipAddrString)
{
struct sockaddr_in hostAddr;
//creates a connection socket (TCP/IP Streaming)
gConnectionToHost = socket(AF_INET, SOCK_STREAM, nil);
//setup addy info for our host
bzero(&hostAddr, sizeof(hostAddr)); //clear
hostAddr.sin_family = AF_INET; //network type internet
hostAddr.sin_port = htons(5500); //our port number
inet_pton(AF_INET, ipAddrString, &hostAddr.sin_addr);
//issue connection request
if (connect(gConnectionToHost, (struct sockaddr *)&hostAddr, sizeof(hostAddr))< 0)
{
printf("CANNOT CONNECT!\n");
}//failed host is not there
if(WriteNetData(gConnectionToHost, "Hello", 32) <=0)
{
printf("FAILED WRITE");
}
}
Send Data Code
int WriteNetData(int socket, void *buffer, int numBytes)
{
Ptr bytes = buffer; //ptr to buffer
int count, n;
n = count =0;
while(count< numBytes) //loop until we have sent all bytes
{
n = send(socket, bytes, numBytes - count, 0); //send..... CRASHES HERE
if(n>0)
{
count += n;
bytes += n;
}
else
if(n<0) //error
return(-1);
}
return(count);
}
Thanks in advance guys