• 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
Socket timing out
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Socket timing out


  • Subject: Socket timing out
  • From: Aaron Alpher <email@hidden>
  • Date: Thu, 18 Jul 2002 16:32:33 -0400

I have setup a socket to a printer using socket() then connect() calls. I then send info across the socket using read() and write(). This works well under normal processing, however if I pause the print and do not send data for more than 2 minutes, the socket apparently times out. Is there a way to prevent this? I am setting the SO_KEEPALIVE and the TCP_KEEPALIVE using setsockopt() but my app still crashes after a 2 minute delay in sending. Is there a way to prevent the timeout? Or perhaps a better way to solve this problem?

Here is my socket setup code:

theSocket = socket( AF_INET, SOCK_STREAM, 0 );
if ( theSocket > 0 )
{
const SInt32 myTrue = 1;

result = setsockopt( theSocket, SOL_SOCKET, SO_KEEPALIVE, &myTrue, sizeof( myTrue ) );
if ( result == 0 )
{
result = setsockopt( theSocket, IPPROTO_TCP, TCP_NODELAY, &myTrue, sizeof( myTrue ) );
if ( result == 0 )
{
result = setsockopt( theSocket, IPPROTO_TCP, TCP_KEEPALIVE, &myTrue, sizeof( myTrue ) );
if ( result == 0 )
{
struct timeval timeoutTime;

timeoutTime.tv_sec = 180;
timeoutTime.tv_usec = 0;

result = setsockopt( theSocket, SOL_SOCKET, SO_SNDTIMEO, &timeoutTime, sizeof( timeoutTime ) );
if ( result == 0 )
{
struct sockaddr_in myAddress;

ClearMemory( &myAddress, sizeof( myAddress ) );
myAddress.sin_family = AF_INET;
myAddress.sin_port = portID;
myAddress.sin_addr.s_addr = theIPAddress;

if ( connect( theSocket, (const sockaddr *) &myAddress, sizeof( myAddress ) ) == 0 )
{
// A successful connection
result = theSocket;
}
}
else
{
DebugMsg( "\psetsockopt( SO_SNDTIMEO ) is invalid" );
}
}
else
{
DebugMsg( "\psetsockopt( TCP_KEEPALIVE ) is invalid" );
}
}
else
{
DebugMsg( "\psetsockopt( TCP_NODELAY ) is invalid" );
}
}
else
{
DebugMsg( "\psetsockopt( SO_KEEPALIVE ) is invalid" );
}
}

Aaron Alpher
Compatable Systems Engineering

101 East Holly Avenue
Suite 1
Sterling, VA 20164 USA

(703) 404-1795
(703) 404-1896 FAX

email@hidden
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Socket timing out
      • From: "Philip D. Wasson" <email@hidden>
  • Prev by Date: Autopush in BSD?
  • Next by Date: Re: Socket timing out
  • Previous by thread: Autopush in BSD?
  • Next by thread: Re: Socket timing out
  • Index(es):
    • Date
    • Thread