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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:48:32+00:00 2026-06-10T23:48:32+00:00

I tried to connect to the server and send some information to the server(like

  • 0

I tried to connect to the server and send some information to the server(like username, password..), and the server send me back the ID (string type). The problem is I can not get the ID. Could anyone help me? I am beginner in IOS coding. Thanks.

Here is the codes:

  1. After I click the button, it will call my own function to get serverIP which is a string and Port which is a int.
  2. Then that function will call this function to connect the server:

    (void)logInCheck {
    
        asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];   
        NSError *error = nil;
        uint16_t port = serverPort;
    
        if (![asyncSocket connectToHost:serverIP onPort:port error:&error])
        {
            DDLogError(@"Unable to connect to due to invalid configuration: %@", error);
        }
        else
        {
            DDLogVerbose(@"Connecting...");
            [self passDataToServer];
        }
    }
    
    //DataPassToServer is a NSString that hold my data
    
    (void)passDataToServer
    {
        NSData *requestData = [DataPassToServer dataUsingEncoding:NSUTF8StringEncoding];
        [asyncSocket writeData:requestData withTimeout:-1.0 tag:0];
        [asyncSocket readDataWithTimeout:-1 tag:0];
    }
    
    //this function call successfully
    
    -(void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
    {
        DDLogVerbose(@"socket:didConnectToHost:%@ port:%hu", host, port);
    }
    
    //this function call successfully
    
    (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
    {
        DDLogVerbose(@"socket:didWriteDataWithTag:");
    }
    
    //This function does not run !!! Nothing print out. 
    
    (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
    {
        DDLogVerbose(@"socket:didReadData:withTag:");
        NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"ID = %@",response);
        [asyncSocket readDataWithTimeout:-1 tag:0];
    }
    
  • 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-06-10T23:48:34+00:00Added an answer on June 10, 2026 at 11:48 pm

    I don’t know about your server implementation but, most implementations would read up to the first newline character before processing the request.

    So make sure that your [DataPassToServer dataUsingEncoding:NSUTF8StringEncoding] includes a newline character ("\n") at the end.

    Your code looks fine and works for me.

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

Sidebar

Related Questions

In sockets I have written the client server program. First I tried to send
I tried this, but I get ERROR: Failed to connect to server: Unable to
I have a client which connects to a server and tries to send() some
I've implemented a simple Flex application that tries to connect to a server via
I tried to connect an Arduino Mega ADK using Demokit sources to several phones
In my code i tried to connect signal from QTrayIcon object and my form
I am learning PHP and tried to connect to MySQL. Altough I am using
as a newbie regarding ActiveMQ, I just tried to connect from Grails to a
I tried to use this snippet from the Soundcloud API: <script src=http://connect.soundcloud.com/sdk.js> <script> SC.initialize({
I tried this: QPushButton* openHostsPushButton = new QPushButton(Open Hosts); Button_SetElevationRequiredState(openHostsPushButton->winId(), true); openHostsPushButton->setMaximumSize(aPushButtonMaxSize); connect(openHostsPushButton, SIGNAL(clicked()),

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.