MOBFTCPClient.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // MOBFSocket.h
  3. // CFNetworkDemo
  4. //
  5. // Created by fenghj on 15/8/18.
  6. // Copyright © 2015年 vimfung. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. /**
  10. * Socket连接处理器
  11. */
  12. typedef void (^MOBFTCPClientConnectedHandler) ();
  13. /**
  14. * Socket断开连接处理器
  15. *
  16. * @param error 错误信息
  17. */
  18. typedef void (^MOBFTCPClientDisconnectedHandler) (NSError *error);
  19. /**
  20. * Socket接收数据处理器
  21. *
  22. * @param data 数据
  23. */
  24. typedef void (^MOBFTCPClientReceiveDataHandler) (NSData *data);
  25. /**
  26. * Socket实现
  27. */
  28. @interface MOBFTCPClient : NSObject
  29. /**
  30. * 主机
  31. */
  32. @property (nonatomic, copy, readonly) NSString *host;
  33. /**
  34. * 端口
  35. */
  36. @property (nonatomic, readonly) UInt32 port;
  37. /**
  38. * 初始化Socket
  39. *
  40. * @param host 主机名称
  41. * @param port 端口号
  42. *
  43. * @return Socket对象
  44. */
  45. - (instancetype)initWithHost:(NSString *)host port:(UInt32)port;
  46. /**
  47. * 连接
  48. *
  49. * @return YES 连接成功,NO 连接失败
  50. */
  51. - (BOOL)connect;
  52. /**
  53. * 断开连接
  54. */
  55. - (void)disconnect;
  56. /**
  57. * 写入数据
  58. *
  59. * @param data 数据
  60. */
  61. - (void)sendData:(NSData *)data;
  62. /**
  63. * 已连接事件
  64. *
  65. * @param handler 事件处理器
  66. */
  67. - (void)onConnected:(MOBFTCPClientConnectedHandler)handler;
  68. /**
  69. * 已断开链接事件
  70. *
  71. * @param handler 事件处理器
  72. */
  73. - (void)onDisconnected:(MOBFTCPClientDisconnectedHandler)handler;
  74. /**
  75. * 接收数据
  76. *
  77. * @param handler 事件处理器
  78. */
  79. - (void)onReceiveData:(MOBFTCPClientReceiveDataHandler)handler;
  80. @end