Is there a mechanism in Objective-C, similar to Netty in Java, for forwarding TCP protocols to UDT in the transport layer

Is there a mechanism in Objective-C, similar to Netty in Java, for forwarding TCP protocols to UDT in Transport Layer.

Now I want to implement an HTTP request and response (running over TCP by default) to start UDT from my application.

  • Is it possible?

  • Is there a built-in mechanism in iOS for this?

+4
source share
2 answers

If you want to use HTTP, I suggest the NSURLConnection class. For example, to use a POST request with headers, do the following:

int kTimeoutInterval = 30;

NSString *post = @"Something to post";
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];


NSString *link = @"http://some_link";
link = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:kTimeoutInterval];

[request setURL:[NSURL URLWithString:link]];

[request setHTTPMethod:@"POST"];
// set some header entries, for example:
//[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[postLength length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

NSError *error;
NSURLResponse* response=nil;
NSData* data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

, , , , , kTimeoutInterval. :

[NSURLConnection connectionWithRequest...

. , , , NSURLConnection. , ...

0

, Netty. CFNetwork, " HTTP-" . CFHTTPMessage, , HTTP- . , , . UDT, .

, / HTTP , - , / .

0

Source: https://habr.com/ru/post/1569519/


All Articles