More Issues

Moderator
Posts: 613
Joined: 2004.09
Post: #1
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
Code:
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
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

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Member
Posts: 116
Joined: 2002.04
Post: #2
1) You're not checking to be sure your socket is valid
2) Call select on the socket before calling send to make sure the socket is available for writing.

Wade
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #3
calling this code before sending data, same error same crash. Yes it returns true.

Code:
static Boolean IsSocketReadyForWrite(int socket)
{
    struct fd_set connectionSet;
    struct timeval timeout;
    int result;
    
    //set timeout values
    timeout.tv_sec =0;
    timeout.tv_usec =0;
    
    FD_ZERO(&connectionSet);
    FD_SET(socket, &connectionSet);
    
    //call select to see if data is waiting on the socket
    result = select(socket+1, nil, &connectionSet, nil, &timeout);
    
    //check results
    if (result < 0 )
        return (false);
    if (result>0)
    {
        if(FD_ISSET(socket, &connectionSet))
            return(true);
        else
            return(false);
    }
    
    return(false);

}

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #4
Are you sure that socket() did not fail? Are you checking the result and calling perror() if necessary?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #5
Socket returns a 6, no other errors besides failure to connect on connect. which i think is related. Anyone want to take a look at my whole source i could email it to you pretty small. Would be very grateful Grin

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Member
Posts: 116
Joined: 2002.04
Post: #6
Well yeah - if it did not connect, you can't send.

Sure, send me your code and I'll take a look. wade at dogwatchsw.com

Wade
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Porting issues (most likely byte order issues) akb825 2 4,354 Mar 24, 2006 11:47 AM
Last Post: DoG