PDA

View Full Version : iPhone listen on TCP/IP with AsyncSocket




Isorinu'
Apr 27, 2009, 02:13 AM
Hello,
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



robbieduncan
Apr 27, 2009, 02:16 AM
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.

Isorinu'
Apr 27, 2009, 02:21 AM
Hello Robbie,

The AsyncSocket class(link (http://code.google.com/p/cocoaasyncsocket/)) 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.

kazimalsaher
Jun 24, 2009, 01:57 AM
Isorinu ,,,

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

Thank you

PhoneyDeveloper
Jun 24, 2009, 11:13 AM
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.

robbieduncan
Jun 24, 2009, 11:16 AM
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.

I already said that above :rolleyes:

rahulgupta.87
Oct 31, 2009, 08:36 PM
Hey,
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.
Thanks

Rahul
Hello,
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

Susanta
Aug 30, 2010, 06:34 AM
Hello,
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

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.

Thanks,
Susanta

globalhawk
Jul 15, 2011, 03:58 AM
Hi,

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.