blob: 9cbd0ec39bfd04b9e9121427fcb6b9b36e03d1f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
//
// TestTCPServer.h
// SmartDeviceLink-iOS
//
// Created by Sho Amano on 2018/07/27.
// Copyright © 2018 Xevo Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Delegate to receive various events from the test TCP server
*/
@protocol TestTCPServerDelegate
- (void)onClientConnected;
- (void)onClientDataReceived:(NSData *)data;
- (void)onClientShutdown;
- (void)onClientError;
@end
@interface TestTCPServer : NSObject
/**
* Sets up a TCP server that listens on specified host and port
*
* Note that this server cannot accept more than one connections from client(s).
*
* @param hostName Host name that the server will listen on
* @param portNumber TCP port number of the server
* @return YES when initialization is successful, NO otherwise
*/
- (BOOL)setup:(NSString *)hostName port:(NSString *)port;
/**
* Shuts down the server, forcefully closing client connection
*
* @return YES when the server is successfully stopped, NO otherwise
*/
- (BOOL)teardown;
/**
* Asynchronously sends data to connected client
*
* @param data Data to send
*/
- (void)send:(NSData *)data;
/**
* Gracefully shuts down the connection between client.
*
* This method triggers shutdown(SHUT_WR) which is to notify that the server does not have any more data to send.
*
* @return YES if shutdown process is succeeded, NO if it's failed or client is not connected
*/
- (BOOL)shutdownClient;
/**
* The delegate to receive server events
*/
@property (nullable, nonatomic, weak) id<TestTCPServerDelegate> delegate;
/**
* Configure this flag to YES to enable SO_REUSEADDR option
*/
@property (nonatomic, assign) BOOL enableSOReuseAddr;
@end
NS_ASSUME_NONNULL_END
|