//
// AsyncUdpSocket.h
//
// This class is in the public domain.
// Originally created by Robbie Hanson on Wed Oct 01 2008.
// Updated and maintained by Deusty Designs and the Mac development community.
//
// http://code.google.com/p/cocoaasyncsocket/
//
#import <Foundation/Foundation.h>
@class AsyncSendPacket;
@class AsyncReceivePacket;
extern NSString *const AsyncUdpSocketException;
extern NSString *const AsyncUdpSocketErrorDomain;
enum AsyncUdpSocketError
{
AsyncUdpSocketCFSocketError = kCFSocketError, // From CFSocketError enum
AsyncUdpSocketNoError = 0, // Never used
AsyncUdpSocketBadParameter, // Used if given a bad parameter (such as an improper address)
AsyncUdpSocketIPv4Unavailable, // Used if you bind/connect using IPv6 only
AsyncUdpSocketIPv6Unavailable, // Used if you bind/connect using IPv4 only (or iPhone)
AsyncUdpSocketSendTimeoutError,
AsyncUdpSocketReceiveTimeoutError
};
typedef enum AsyncUdpSocketError AsyncUdpSocketError;
@interface AsyncUdpSocket : NSObject
{
CFSocketRef theSocket4; // IPv4 socket
CFSocketRef theSocket6; // IPv6 socket
CFRunLoopSourceRef theSource4; // For theSocket4
CFRunLoopSourceRef theSource6; // For theSocket6
CFRunLoopRef theRunLoop;
CFSocketContext theContext;
NSArray *theRunLoopModes;
NSMutableArray *theSendQueue;
AsyncSendPacket *theCurrentSend;
NSTimer *theSendTimer;
NSMutableArray *theReceiveQueue;
AsyncReceivePacket *theCurrentReceive;
NSTimer *theReceiveTimer;
id theDelegate;
UInt16 theFlags;
long theUserData;
NSString *cachedLocalHost;
UInt16 cachedLocalPort;
NSString *cachedConnectedHost;
UInt16 cachedConnectedPort;
UInt32 maxReceiveBufferSize;
}
/**
* Creates new instances of AsyncUdpSocket.
**/
- (id)init;
- (id)initWithDelegate:(id)delegate;
- (id)initWithDelegate:(id)delegate userData:(long)userData;
/**
* Creates new instances of AsyncUdpSocket that support only IPv4 or IPv6.
* The other init methods will support both, unless specifically binded or connected to one protocol.
* If you know you'll only be using one protocol, these init methods may be a bit more efficient.
**/
- (id)initIPv4;
- (id)initIPv6;
- (id)delegate;
- (void)setDelegate:(id)delegate;
- (long)userData;
- (void)setUserData:(long)userData;
/**
* Returns the local address info for the socket.
*
* Note: Address info may not be available until after the socket has been bind'ed,
* or until after data has been sent.
**/
- (NSString *)localHost;
- (UInt16)localPort;
/**
* Returns the remote address info for the socket.
*
* Note: Since UDP is connectionless by design, connected address info
* will not be available unless the socket is explicitly connected to a remote host/port
**/
- (NSString *)connectedHost;
- (UInt16)connectedPort;
/**
* Returns whether or not this socket has been connected to a single host.
* By design, UDP is a connectionless protocol, and connecting is not needed.
* If connected, the socket will only be able to send/receive data to/from the connected host.
**/
- (BOOL)isConnected;
/**
* Returns whether or not this socket has been closed.
* The only way a socket can be closed is if you explicitly call one of the close methods.
**/
- (BOOL)isClosed;
/**
* Returns whether or not this socket supports IPv4.
* By default this will be true, unless the socket is specifically initialized as IPv6 only,
* or is binded or connected to an IPv6 address.
**/
- (BOOL)isIPv4;
/**
* Returns whether or not this socket supports IPv6.
* By default this will be true, unless the socket is specifically initialized as IPv4 only,
* or is binded or connected to an IPv4 address.
*
* This method will also return false on platforms that do not support IPv6.
* Note: The iPhone does not currently support IPv6.
**/
- (BOOL)isIPv6;
/**
* Returns the mtu of the socket.
* If unknown, returns zero.
*
* Sending data larger than this may result in an error.
* This is an advanced topic, and one should understand the wide range of mtu's on networks and the internet.
* Therefore this method is only for reference and may be of little use in many situations.
**/
- (unsigned int)maximumTransmissionUnit;
/**
* Binds the UDP socket to the given port and optional address.
* Binding should be done for server sockets that receive data prior to sending it.
* Client sockets can skip binding,
* as the OS will automatically assign the socket an available port when it starts sending data.
*
* You cannot bind a socket after its been connected.
* You can only bind a socket once.
* You can still connect a socket (if desired) after binding.
*
* On success, returns YES.
* Otherwise returns NO, and sets errPtr. If you don't care about the error, you can pass nil for errPtr.
**/
- (BOOL)bindToPort:(UInt16)port error:(NSError **)errPtr;
- (BOOL)bindToAddress:(NSString *)localAddr port:(UInt16)port error:(NSError **)errPtr;
/**
* Connects the UDP socket to the given host and port.
* By design, UDP is a connectionless protocol, and connecting is not needed.
*
* Choosing to connect to a specific host/port has the following effect:
* - You will only be able to send data to the connected host/port.
* - You will only be able to receive data from the connected host/port.
* - You will receive ICMP messages that come from the connected host/port, such as "connection refused".
*
* Connecting a UDP socket does not result in any communication on the socket.
* It simply changes the internal state of the socket.
*
* You cannot bind a socket after its been connected.
* You can only connect a socket once.
*
* On success, returns YES.
* Otherwise returns NO, and sets errPtr. If you don't care about the error, you can pass nil for errPtr.
**/
- (BOOL)connectToHost:(NSString *)host onPort:(UInt16)port error:(NSError **)errPtr;
- (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
/**
* Join multicast group
*
* Group should be an IP address (eg @"225.228.0.1")
**/
- (BOOL)joinMulticastGroup:(NSString *)group error:(NSError **)errPtr;
- (BOOL)joinMulticastGroup:(NSString *)group withAddress:(NSString *)interface error:(NSError **)errPtr;
/**
* By default, the underlying socket in the OS will not allow you to send broadcast messages.
* In order to send broadcast messages, you need to enable this functionality in the socket.
*
* A broadcast is a UDP message to addresses like "192.168.255.255" or "255.255.255.255" that is
* delivered to every host on the network.
* The reason this is generally disabled by default is to prevent
* accidental broadcast messages from flooding the network.
**/
- (BOOL)enableBroadcast:(BOOL)flag error:(NSError **)errPtr;
/**
* Asynchronously sends the given data, with the given timeout and tag.
*
* This method may only be used with a connected socket.
*
* If data is nil or zero-length, this method does nothing and immediately returns NO.
* If the socket is not connected, this method does nothing and immediately returns NO.
**/
- (BOOL)sendData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
/**
* Asynchronously sends the given data, with the given timeout and tag, to the given host and port.
*
* This method cannot be used with a connected socket.
*
* If data is nil or zero-length, this method does nothing and immediately returns NO.
* If the socket is connected, this method does nothing and immediately returns NO.
* If unable to resolve host to a valid IPv4 or IPv6 address, this method returns NO.
**/
- (BOOL)sendData:(NSData *)data toHost:(NSString *)host port:(UInt16)port withTimeout:(NSTimeInterval)timeout tag:(long)tag;
/**
* Asynchronously sends the given data, with the given timeout and tag, to the given address.
*
* This method cannot be used with a connected socket.
*
* If data is nil or zero-length, this method does nothing and immediately returns NO.
* If the s
没有合适的资源?快使用搜索试试~ 我知道了~
NTP_Component.framework for ios
共11个文件
h:5个
ntp_component:3个
current:1个
3星 · 超过75%的资源 需积分: 13 76 下载量 10 浏览量
2012-08-02
10:35:20
上传
评论 2
收藏 280KB ZIP 举报
温馨提示
基于jbenet/ios-ntp开源代码以及CSDN资源《ntp客户端实现 for ios》封装的NTPframework。 使用方法:解压后拷贝framework文件夹到工程目录并添加到工程中,再添加CFNetwork.framework即可使用。 在viewcontroller中调用[[NetworkClock sharedNetworkClock] updateDate]; 并实现GetNTPDateDelegate的-(void)getNTPDate:(NSDate *)date方法,参数的date就是取得的网络标准时间,可以在getNTPDate方法中随意设定地域信息及格式后设定画面表示
资源推荐
资源详情
资源评论
收起资源包目录
framework.zip (11个子文件)
framework
NTP_Component 371KB
NTP_Component.framework
Resources 26B
Versions
Current 1B
A
Resources
NTP_Component 371KB
Headers
ios-ntp.h 1KB
NetAssociation.h 8KB
NetworkClock.h 3KB
SynthesizeSingleton.h 1KB
AsyncUdpSocket.h 14KB
NTP_Component 30B
Headers 24B
共 11 条
- 1
资源评论
- iflychenyang2014-01-13很好,但是手机退后台,返回后再调用接口会崩溃
無双
- 粉丝: 47
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功