FMAsyncSocketDelegate Protocol Reference

Declared in FM.h

– onSocket:willDisconnectWithError:

In the event of an error, the socket is closed. You may call “unreadData” during this call-back to get the last bit of data off the socket. When connecting, this delegate method may be called before"onSocket:didAcceptNewSocket:“ or "onSocket:didConnectToHost:”.

- (void)onSocket:(FMAsyncSocket *)sock willDisconnectWithError:(NSError *)err

Discussion

In the event of an error, the socket is closed. You may call “unreadData” during this call-back to get the last bit of data off the socket. When connecting, this delegate method may be called before"onSocket:didAcceptNewSocket:“ or "onSocket:didConnectToHost:”.

Declared In

FM.h

– onSocketDidDisconnect:

Called when a socket disconnects with or without error. If you want to release a socket after it disconnects, do so here. It is not safe to do that during “onSocket:willDisconnectWithError:”.

- (void)onSocketDidDisconnect:(FMAsyncSocket *)sock

Discussion

Called when a socket disconnects with or without error. If you want to release a socket after it disconnects, do so here. It is not safe to do that during “onSocket:willDisconnectWithError:”.

If you call the disconnect method, and the socket wasn’t already disconnected, this delegate method will be called before the disconnect method returns.

Declared In

FM.h

– onSocket:didAcceptNewSocket:

Called when a socket accepts a connection. Another socket is spawned to handle it. The new socket will have the same delegate and will call “onSocket:didConnectToHost:port:”.

- (void)onSocket:(FMAsyncSocket *)sock didAcceptNewSocket:(FMAsyncSocket *)newSocket

Discussion

Called when a socket accepts a connection. Another socket is spawned to handle it. The new socket will have the same delegate and will call “onSocket:didConnectToHost:port:”.

Declared In

FM.h

– onSocket:wantsRunLoopForNewSocket:

Called when a new socket is spawned to handle a connection. This method should return the run-loop of the thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used.

- (NSRunLoop *)onSocket:(FMAsyncSocket *)sock wantsRunLoopForNewSocket:(FMAsyncSocket *)newSocket

Discussion

Called when a new socket is spawned to handle a connection. This method should return the run-loop of the thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used.

Declared In

FM.h

– onSocketWillConnect:

Called when a socket is about to connect. This method should return YES to continue, or NO to abort. If aborted, will result in FMAsyncSocketCanceledError.

- (BOOL)onSocketWillConnect:(FMAsyncSocket *)sock

Discussion

Called when a socket is about to connect. This method should return YES to continue, or NO to abort. If aborted, will result in FMAsyncSocketCanceledError.

If the connectToHost:onPort:error: method was called, the delegate will be able to access and configure the CFReadStream and CFWriteStream as desired prior to connection.

If the connectToAddress:error: method was called, the delegate will be able to access and configure the CFSocket and CFSocketNativeHandle (BSD socket) as desired prior to connection. You will be able to access and configure the CFReadStream and CFWriteStream in the onSocket:didConnectToHost:port: method.

Declared In

FM.h

– onSocket:didConnectToHost:port:

Called when a socket connects and is ready for reading and writing. The host parameter will be an IP address, not a DNS name.

- (void)onSocket:(FMAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port

Discussion

Called when a socket connects and is ready for reading and writing. The host parameter will be an IP address, not a DNS name.

Declared In

FM.h

– onSocket:didReadData:withTag:

Called when a socket has completed reading the requested data into memory. Not called if there is an error.

- (void)onSocket:(FMAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag

Discussion

Called when a socket has completed reading the requested data into memory. Not called if there is an error.

Declared In

FM.h

– onSocket:didReadPartialDataOfLength:tag:

Called when a socket has read in data, but has not yet completed the read. This would occur if using readToData: or readToLength: methods. It may be used to for things such as updating progress bars.

- (void)onSocket:(FMAsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag

Discussion

Called when a socket has read in data, but has not yet completed the read. This would occur if using readToData: or readToLength: methods. It may be used to for things such as updating progress bars.

Declared In

FM.h

– onSocket:didWriteDataWithTag:

Called when a socket has completed writing the requested data. Not called if there is an error.

- (void)onSocket:(FMAsyncSocket *)sock didWriteDataWithTag:(long)tag

Discussion

Called when a socket has completed writing the requested data. Not called if there is an error.

Declared In

FM.h

– onSocket:didWritePartialDataOfLength:tag:

Called when a socket has written some data, but has not yet completed the entire write. It may be used to for things such as updating progress bars.

- (void)onSocket:(FMAsyncSocket *)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(long)tag

Discussion

Called when a socket has written some data, but has not yet completed the entire write. It may be used to for things such as updating progress bars.

Declared In

FM.h

– onSocket:shouldTimeoutReadWithTag:elapsed:bytesDone:

Called if a read operation has reached its timeout without completing. This method allows you to optionally extend the timeout. If you return a positive time interval (> 0) the read’s timeout will be extended by the given amount. If you don’t implement this method, or return a non-positive time interval (<= 0) the read will timeout as usual.

- (NSTimeInterval)onSocket:(FMAsyncSocket *)sock shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length

Discussion

Called if a read operation has reached its timeout without completing. This method allows you to optionally extend the timeout. If you return a positive time interval (> 0) the read’s timeout will be extended by the given amount. If you don’t implement this method, or return a non-positive time interval (<= 0) the read will timeout as usual.

The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method. The length parameter is the number of bytes that have been read so far for the read operation.

Note that this method may be called multiple times for a single read if you return positive numbers.

Declared In

FM.h

– onSocket:shouldTimeoutWriteWithTag:elapsed:bytesDone:

Called if a write operation has reached its timeout without completing. This method allows you to optionally extend the timeout. If you return a positive time interval (> 0) the write’s timeout will be extended by the given amount. If you don’t implement this method, or return a non-positive time interval (<= 0) the write will timeout as usual.

- (NSTimeInterval)onSocket:(FMAsyncSocket *)sock shouldTimeoutWriteWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length

Discussion

Called if a write operation has reached its timeout without completing. This method allows you to optionally extend the timeout. If you return a positive time interval (> 0) the write’s timeout will be extended by the given amount. If you don’t implement this method, or return a non-positive time interval (<= 0) the write will timeout as usual.

The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method. The length parameter is the number of bytes that have been written so far for the write operation.

Note that this method may be called multiple times for a single write if you return positive numbers.

Declared In

FM.h

– onSocketDidSecure:

Called after the socket has successfully completed SSL/TLS negotiation. This method is not called unless you use the provided startTLS method.

- (void)onSocketDidSecure:(FMAsyncSocket *)sock

Discussion

Called after the socket has successfully completed SSL/TLS negotiation. This method is not called unless you use the provided startTLS method.

If a SSL/TLS negotiation fails (invalid certificate, etc) then the socket will immediately close, and the onSocket:willDisconnectWithError: delegate method will be called with the specific SSL error code.

Declared In

FM.h