iOS Advanced TCP proxy authentication process

Source: Internet
Author: User

This time in contact with the network agent, and its own task is to complete the TCP and UDP network proxy, so write some of their own understanding here.

This article first introduces the TCP proxy authentication process (using the user name and password Authentication), the next article introduces the authentication process of UDP proxy.

I wrote a demo of the SDK, the main use is cocoaasyncsocket in the Gcdasyncsocket and Gcdasyncudpsocket. Other files to use see

    

Create Sjxtcpsocketclient, inherited from Nsurlprotocol. Add key member variables and methods in the. h file, such as

    

Add an object in the. m file that records the communication pipeline, which holds the pipeline for TCP local and remote communication, and makes corresponding communication operations.

    

The first step: Set the TCP proxy address and port, and turn on listening.

    

Step two: When Urlprotocol intercepts the TCP request, the Didacceptnewsocket is called and the connection to the TCP local communication pipeline is set.

    

Third step:-(void) Socket: (Gcdasyncsocket *) sock didreaddata: (NSData *) data withtag: (long) tag will respond to determine the tag tag of the previous operation, Establishes a connection to the TCP local communication pipeline.

    

Fourth step:-(void) Socket: (Gcdasyncsocket *) sock Didwritedatawithtag: (long) The tag responds, determines the tag tag of the previous operation, and completes the connection to the TCP local communication pipeline.

    

Fifth step:-(void) Socket: (Gcdasyncsocket *) sock didreaddata: (NSData *) data withtag: (long) tag responds, according to the tag tag, set the way to negotiate with the remote connection.

    

This is used to negotiate the user name and password, and to set up a connection to the TCP remote communication pipeline.

    

Sixth step: Didconnecttohost will respond, start with Proxy server first step authentication operation

    

According to your own needs, to complete the data you need, here take 050102 for example

    

Seventh step: Here will respond to Didwritedatawithtag, and then set the read data, let the didreaddata response, the proxy server returns data to the first step of the authentication result judgment. If the first step authentication success, according to their own requirements to set the corresponding user name and password, the user name and password according to the requirements of the correct data sent to the proxy server, and the proxy server for the second step authentication operation.

    

    

The eighth step: the same here will respond to Didwritedatawithtag, and then set the read data, let the didreaddata response, here to the proxy server return data for the second step of the authentication result judgment. If the second step authentication is passed, the proxy server attempts to connect to the target server.

    

Nineth Step: The response of Didwritedatawithtag and Didreaddata, if the proxy server and the target server to connect successfully, you can make TCP proxy forwarding data.

    

Wrote a demo for your reference. I hope the great God will correct you.

Github:https://github.com/sjxjjx/sjxsocket

iOS Advanced TCP proxy authentication process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.