Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 638877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:46:49+00:00 2026-05-13T20:46:49+00:00

My code was working absolutely fine before the launch of iPhone SDK 3.0 ,

  • 0

My code was working absolutely fine before the launch of iPhone SDK 3.0 , I am using socket functions to send data and receive data. What changes must i make to make it compatible for 3.0+.

-(int)InitSocket:(int)nPort: (NSString*)sServer{

if(sServer == nil)
{
    return -1;
}
m_nPort = nPort;
sServerAddress = sServer;

const char* pServer = nil;
pServer = [sServer cStringUsingEncoding:NSASCIIStringEncoding];

m_nSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);


struct sockaddr_in servAddr;
memset(&servAddr, 0 , sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = inet_addr(pServer);
servAddr.sin_port = htons(m_nPort);

pfd.fd = m_nSock;
pfd.events = POLLIN | POLLERR| POLLHUP | POLLNVAL;
pfd.revents = 0;

m_nTimeout = -1;

int f = fcntl(m_nSock, F_GETFL, 0);
fcntl(m_nSock, F_SETFL, f | O_NONBLOCK |O_NDELAY);

int opt = 1;
setsockopt(m_nSock, SOL_SOCKET, SO_KEEPALIVE, (const void*)&opt,(socklen_t)sizeof(opt));


struct timeval timeout;
fd_set wset;
FD_ZERO(&wset);
FD_SET(m_nSock, &wset);
timeout.tv_sec = 2;
timeout.tv_usec = 0;

return 0;

}

This Code for sending data

-(int)SendData:(size_t) nSize: (NSString*) buffer{

int nTotalSent = 0;
const char *pSend =  [buffer cStringUsingEncoding:NSASCIIStringEncoding];

while(nTotalSent != nSize)
{
            int nSent = send(m_nSock, (const void*)pSend+nTotalSent, nSize-nTotalSent, 0);
    if(nSent == -1)
    {
        return nSent;
    }
    nTotalSent += nSent;
}

return nTotalSent;

}

Will the above code works in iPhone SDK 3.0+ , what changes i need to employ to make it work.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:46:49+00:00Added an answer on May 13, 2026 at 8:46 pm

    You could start by properly checking for errors. All those functions that you use return an error code if something goes wrong and you will never know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is really strange but this code is working fine unless the value entered
I have this code, which is working fine in FireFox, chrome and IE8 but
I've used this code in another site I've made and it works absolutely fine
I'm trying to get some code working that a previous developer has written. Yep,
I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user
I'm trying to get this piece of code working a little better. I suspect
I asked how to render a UserControl's HTML and got the code working for
Ok, so I'm trying to get some UDP code working and I'm barely green
EDIT: See my working code in the answers below. In brief: I have a
I am working on code generation and ran into a snag with generics. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.