Inherits from NSObject
Declared in YLTCPBroadcaster.h

Overview

An YLTCPBroadcaster object allows you to find every host on the specified network with a given TCP port open. E.g. find on your local network every hosts with the port 8080 open.

YLTCPBroadcaster is fully GCD (Grand Central Dispatch) based and Thread-Safe.

It works by broadcasting a TCP connection to every host on the network (using the subnet mask) and by waiting the response for each one. In this manner it can determine whether the host is open on the given port.

Properties

broadcastAddress

The receiver’s broadcast address.

@property (nonatomic, strong, readonly) NSString *broadcastAddress

Availability

1.0.0

Declared In

YLTCPBroadcaster.h

ip

The receiver’s ip address.

@property (nonatomic, strong, readonly) NSString *ip

Availability

1.0.0

Declared In

YLTCPBroadcaster.h

networkPrefix

The receiver’s network prefix address.

@property (nonatomic, strong, readonly) NSString *networkPrefix

Availability

1.0.0

Declared In

YLTCPBroadcaster.h

subnetMask

The receiver’s subnet mask.

@property (nonatomic, strong, readonly) NSString *subnetMask

Availability

1.0.0

Declared In

YLTCPBroadcaster.h

Class Methods

broadcasterWithIp:subnetMask:

Creates a broadcaster with an ip and its subnet mask.

+ (instancetype)broadcasterWithIp:(NSString *)ip subnetMask:(NSString *)subnetMask

Parameters

ip

The ip of the receiver.

subnetMask

The subnet mask corresponding to the ip.

Availability

1.0.0

Declared In

YLTCPBroadcaster.h

defaultBroadcaster

Creates and returns the default broadcaster.

+ (instancetype)defaultBroadcaster

Availability

1.0.0

Discussion

The default broadcaster corresponding to the default device network. It means the broadcaster’s ip, subnetMask, networkPrefix and broadcastAddress are the same of the current device.

Declared In

YLTCPBroadcaster.h

Instance Methods

initWithIp:subnetMask:

Initializes a broadcaster with an ip and its subnet mask.

- (id)initWithIp:(NSString *)ip subnetMask:(NSString *)subnetMask

Parameters

ip

The ip of the receiver.

subnetMask

The subnet mask corresponding to the ip.

Availability

1.0.0

Discussion

In order to perform the request the ip and the subnet mask should be the same of the current device.

Declared In

YLTCPBroadcaster.h

scanWithPort:completionHandler:

Performs an asynchronous scan of the current network to find every host which are listening on a given TCP port number.

- (void)scanWithPort:(SInt32)port completionHandler:(YLTCPBroadcasterCompletionBlock)completionBlock

Parameters

port

The TCP port number to which the socket should connect.

completionBlock

A broadcaster completion block.

Availability

1.0.0

Discussion

The operation is performed with the kYLTCPSocketDefaultTimeoutInSeconds timeout value.

Declared In

YLTCPBroadcaster.h

scanWithPort:timeoutInterval:completionHandler:

Performs an asynchronous scan of the current network to find every host which are listening on a given TCP port number. The operation is stopped if the time exceeded the timeout.

- (void)scanWithPort:(SInt32)port timeoutInterval:(NSTimeInterval)timeout completionHandler:(YLTCPBroadcasterCompletionBlock)completionBlock

Parameters

port

The TCP port number to which the socket should connect.

timeout

The timeout interval for the operation, in seconds.

completionBlock

A broadcaster completion block.

Availability

1.0.0

Discussion

The operation runs entirely within its own GCD dispatch_queue and it calls the completion handler on the main queue when it finishes. If no host is found and/or if an error occured the returned list is empty.

Declared In

YLTCPBroadcaster.h