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 6791349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:08+00:00 2026-05-26T17:50:08+00:00

I’ve programmed a client-server application for Android and I’m doing the same for Iphone.

  • 0

I’ve programmed a client-server application for Android and I’m doing the same for Iphone.
The thing is that for the communication process, with the java server and the Android client, I’ve programmed something like this (in pseudo…):

data = read();
if ( data.compareTo("Something1") == 0) then
     write("Something2");
     data = read();
     if ( data.compareTo("Something3") == 0) then
          //End communitacion
     endif
endif

Now my problem is that with the “iphone sockets” I don’t know how to do that. I’m using the AsyncScoket library, and with that library the read is not blocking (something that is complicated for me) and it uses callbacks that I don’t really know how to use it correctly.

I guess that when a read is done, I should test in the proper callback if the data sent is equal to “Something1” or “Something2″… But, the first little problem is that it doesn’t have any order.

I should say that I have no time to modify the protocol.

If someone could guide me, I would be so grateful. Or any code example where a network communication is done with the AsyncSocket library.

Thank you!

  • 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-26T17:50:09+00:00Added an answer on May 26, 2026 at 5:50 pm

    I’ve recently begun using asyncsocket along with a TCP java server. Perhaps this code may help?

    To write to the socket you need to call the following method from the asyncsocket object

    -(void)writeData:withTimeout:tag:;
    

    Data here should be an NSData object. You can easily convert strings to NSData by doing

    [someStringObject dataUsingEncoding:NSUTF8Encoding];
    

    To read from the socket just call this method

    -(void)readDataWithTimeOut:tag:;
    

    pass -1 for the timeout if you do not need a timeout.

    And that’s it. Reading/Writing using cocoaasyncsocket is much easier than dealing with sockets in Java where you need datainputstream and dataoutputstream and other such stuff.

    Important delegate methods are

    -(void)onSocket:didReadData:withTag: gets called whenever the socket reads some data.
    

    Example of this delegate is..

    -(void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{
    
          NSString *string = [[NSString alloc] initWithBytes:[data bytes] 
                                                      length:[data length]
                                                    encoding:NSUTF8StringEncoding];
         //Do what ever comparison you'd like here.
    
    }
    

    If there is anything that you don’t understand then let me know and I’ll try and answer your doubts.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.