iPhone listen on TCP/IP with AsyncSocket

Discussion in 'iOS Programming' started by Isorinu', Apr 27, 2009.

  1. Isorinu' macrumors newbie

    Oct 16, 2008
    i'm writing a little app for iphone that needs to comunicate over TCP/IP with a C# server. My iphone app is working..it can send and receive data from the C# server after connecting to it(for that i am using the AsyncSocket class from google code project), the C# server also can send and receive data from/to the iphone app.

    my problem is when the iphone app receives a message from the server it can't display it right away. for example i have a UILabel serverMessage. If i read the data from the socket and i say serverMessage.Text = (data from the socket) it will not show the message sent... but if i reload the view the data send from the server it will be available...

    this problem that i have does not resume only in the case when i want to show the data sent by the server but also when i try to access it after reading it from the socket.

    any ideas? i found on another site a similar problem but they resolved it by making another thread for listening on the port.. also they used notifications..when something was received the views registered to receive notification would act..

    it sounded like a very good idea..but when i hear about threading i'm a little in the dark...

    thank you in advance
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Does AsyncSocket use a secondary thread to achieve it's async behaviour? If so try updating your UI on the main thread as updates from other threads don't work.
  3. Isorinu' thread starter macrumors newbie

    Oct 16, 2008
    Hello Robbie,

    The AsyncSocket class(link) is Run-loop based, not thread based. On google code it says that it can be used on main or worker threads, but it doesn't have to. It calls the delegate methods asynchronously using NSRunLoop. The delegate methods include a socket parameter, allowing you to distinguish between many instances.
  4. kazimalsaher macrumors newbie

    Jun 23, 2009
    Isorinu ,,,

    did you find he solution? please advice, I am trying to do the same thing!

    Thank you
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    You can't update the UI from a background thread. You can use performSelectorOnMainThread from a background thread and update the UI from that call.
  6. robbieduncan Moderator emeritus


    Jul 24, 2002
    I already said that above :rolleyes:
  7. rahulgupta.87 macrumors newbie

    Oct 26, 2009
    Help iPhone <---> Windows Communication

    I am trying to connect iPhone and Windows.. Having some problem with the same for coding stuff for the client(iPhone)
    Please help by sharing your accomplishment.

  8. Susanta macrumors newbie

    Aug 30, 2010
    Source code of C# ASyncSocket

    I have downloaded both the AsyncSocket code for iPhone and C# from http://code.google.com/p/cocoaasyncsocket/ & http://www.deusty.com/opensource/downloads/WinAsyncSocket.zip.
    But I am not able to do a data transmission using these code between iPhone and C# server. I have a doubt whether i have the updated code for the C# server as it is mentioned it can be downloaded from Google code, but there is nothing on the http://code.google.com/p/dotnetasyncsocket/

    Can you please let me know from where I can download the latest code? If you can help to send me sample working for both iPhone and C# server, that will be great.

    Any help is really appreciated.

  9. globalhawk macrumors newbie

    Jul 15, 2011

    I am trying to do the same thing. iPhone as a client (CocoaAsyncSocket) and PC as a server (C#). Can anyone share their basic codes with me? Many many thanks.

Share This Page