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

  • SEARCH
  • Home
  • 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 3432126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:24:38+00:00 2026-05-18T07:24:38+00:00

I do have a java server. I am trying to build IPhone application that

  • 0

I do have a java server. I am trying to build IPhone application that connect to the server. Also sends and receives messages. I a little confused about using CFReadStreamRef and CFWriteStreamRef. How can I pair the socket with the streams successfully. This is what i have:

fd = socket(AF_INET, SOCK_STREAM, 0);
emset(&addr, 0, sizeof(addr));
addr.sin_len    = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port   = htons(port);//0;
inet_aton("192.168.1.101", &addr.sin_addr.s_addr);

CFSocketContext context = { 0, self, NULL, NULL, NULL };

listeningSocket = CFSocketCreateWithNative( NULL, fd,kCFSocketConnectCallBack, AcceptCallback, &context);

CFDataRef connectAddr = CFDataCreate(NULL, (unsigned char *)&addr, sizeof(addr));
CFSocketConnectToAddress(self.listeningSocket, connectAddr, -1);

// As soon as i get the Connect call back into my function I try to pair the streams to the socket
CFReadStreamRef     readStreamm;
CFWriteStreamRef    writeStreamm;

CFStreamCreatePairWithSocket(NULL, CFSocketGetNative(listeningSocket), &readStreamm, &writeStreamm);
[readStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

[readStream open];
[writeStream open];

However when i try to write or read from the stream is returning an error (-1). Another question I have if I use readStream or writeStream open, and if it was successful. Is that mean that I am already connected to the server?? or do I actually have to call CFSocketConnectToAddress . I am just trying to figure out if i need to use both the connectToAdderss and stream open. Or I should use one or the other.

Thanks in advance.

  • 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-18T07:24:39+00:00Added an answer on May 18, 2026 at 7:24 am

    I recommend using cocoaasyncsocket. Its is a lightweight wrapper to make socket-based communication much easier. Just now I am workin on communication between iPhone and a network device. It works flawless.

    [sock writeData:[@"Hello World" dataUsingEncoding:NSUTF8StringEncoding] withTimeout:-1 tag:1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a server - client application that runs on java 1.3; i want
I have a very simple Java RMI Server that looks like the following: import
I have a server written in Java that runs as a Windows service (thanks
I have a client-server application written in Java using CORBA for the communication. The
I have a server behind a firewall. It runs a web application (Java servlets
I have a piece of server-ish software written in Java to run on Windows
Hey all. I have a server written in java using the ServerSocket and Socket
I have a distributed Java application running on 5 application servers. The servers all
I m trying to install Glassfish Application Server 3.1. But I get this I
I'm trying to incorporate server-based code diff and highlighting in my GWT (Java) project.

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.