I know developers can set http proxy server like the following codes: when send a http request, the local server(127.0.0.1:6000) will receive the http request.
Now I want to set socket proxy server: when the socket client send a socket message to a remote server, the local server(127.0.0.1:6000) will receive socket message.
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
return request;
}
+ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b {
return [super requestIsCacheEquivalent:a toRequest:b];
}
+ (void)setLocalPort:(NSInteger)localPort {
ssLocalPort = localPort;
}
- (void)startLoading
{
if (!session) {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.connectionProxyDictionary =
@{(NSString *)kCFStreamPropertySOCKSProxyHost: @"127.0.0.1",
(NSString *)kCFStreamPropertySOCKSProxyPort: @(6000)};
session = [NSURLSession sessionWithConfiguration:configuration];
}
// ...
}