> When the connection is established, the
> onSocket:didConnectToHost:onPort: delegate method will be called.
> Once this method is called, you know the socket is connected. The
> delegate method will be called in the same thread that you started the
> socket in. (So you don't have to worry about all those crazy
> threading issues. All delegate methods will be invoked in the proper
> thread.)
Okay, and how can I check this in my source?
Something like: if (connectionEstablished) { do something }?
> > My server is an EchoServer. How can I receive this echo message?
> > [asyncSock readDataWithTimeout:0.500 tag:1];
> > How can I get the message text?
>
> The way you use the AsyncSocket is dependent upon the protocol you're
> using it for. E.g HTTP, POP3, IMAP, etc.
I see the different readData methods in the source code.
> If you're working with an EchoServer, these terminate each message
> with an ending CRLF (carriage return, line feed). So you can do
> something like this:
>
> [asyncSocket readDataToTerm:[AsyncSocket CRLFData] withTimeout:-1.0
> tag:0];
It must be "readDataToData" instead of "readDataToTerm"?
My source code:
NSString* str= @"test\r\n";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
[asyncSocket writeData:data withTimeout:0.300 tag:1];
[asyncSocket readDataToData:[AsyncSocket CRLFData] withTimeout:-1.0
tag:0];
How can I access the response message? I want to print it for example
via NSLog().
But now I have to use the "delegate methods"? Because if I call the
method to write the data to the server, it could be possible if I call
the method readDataToData the message isn't send at this time and
therefore the server can't send me the echo?
Thanks & Regards.