FBTCPSocket.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "GCDAsyncSocket.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @protocol FBTCPSocketDelegate
  12. /**
  13. The callback which is fired on new TCP client connection
  14. @param newClient The newly connected socket
  15. */
  16. - (void)didClientConnect:(GCDAsyncSocket *)newClient;
  17. /**
  18. The callback which is fired when the TCP server receives a data from a connected client
  19. @param client The client, which sent the data
  20. */
  21. - (void)didClientSendData:(GCDAsyncSocket *)client;
  22. /**
  23. The callback which is fired when TCP client disconnects
  24. @param client The actual diconnected client
  25. */
  26. - (void)didClientDisconnect:(GCDAsyncSocket *)client;
  27. @end
  28. @interface FBTCPSocket : NSObject
  29. @property (nullable, nonatomic) id<FBTCPSocketDelegate> delegate;
  30. /**
  31. Creates TCP socket isntance which is going to be started on the specified port
  32. @param port The actual port number
  33. @return self instance
  34. */
  35. - (instancetype)initWithPort:(uint16_t)port;
  36. /**
  37. Starts TCP socket listener on the specified port
  38. @param error The alias to the actual startup error descirption or nil if the socket has started and is listening
  39. @return NO If there was an error
  40. */
  41. - (BOOL)startWithError:(NSError **)error;
  42. /**
  43. Stops the socket if it is running
  44. */
  45. - (void)stop;
  46. @end
  47. NS_ASSUME_NONNULL_END