CN114500681A - Network request connection method, device, medium and computer equipment - Google Patents

Network request connection method, device, medium and computer equipment Download PDF

Info

Publication number
CN114500681A
CN114500681A CN202011157709.4A CN202011157709A CN114500681A CN 114500681 A CN114500681 A CN 114500681A CN 202011157709 A CN202011157709 A CN 202011157709A CN 114500681 A CN114500681 A CN 114500681A
Authority
CN
China
Prior art keywords
connection
protocol
interface
class
network request
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011157709.4A
Other languages
Chinese (zh)
Inventor
周志刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN202011157709.4A priority Critical patent/CN114500681A/en
Publication of CN114500681A publication Critical patent/CN114500681A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/28Timers or timing mechanisms used in protocols

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a network request connection method, a device, a medium and computer equipment, comprising the following steps: creating a first protocol connection socket class and a second protocol connection socket class; creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class; creating a connection class, and creating a corresponding interface and a member variable in the connection class; when a network request is received, judging whether proxy information exists or not, and if not, determining a short connection protocol used by the network request; calling a corresponding protocol connection socket class by using an external connection interface, and establishing a network request connection according to the protocol connection socket class; the socket classes supporting different protocols are created in advance, different socket classes have uniform external connection interfaces, and a caller only needs to call the external connection interfaces without searching the interface corresponding to the protocol, so that the connection process of a network request is simplified, and the connection efficiency is ensured.

Description

Network request connection method, device, medium and computer equipment
Technical Field
The present invention relates to the field of network connection technologies, and in particular, to a method, an apparatus, a medium, and a computer device for connecting a network request.
Background
For the current short connection protocol of the client, functions to be supported include an http protocol, an https protocol and a proxy protocol. And the logic implemented for each protocol session is not the same. And thus the way in which they are embodied in connection is different.
Therefore, for different short connection protocols, the prior art needs to provide 3 sockets externally to implement different protocol connections respectively. The external interfaces are not uniform, when a caller calls a corresponding connection protocol, the caller needs to determine which protocol the network request is, and then searches for the corresponding interface to call, so that the calling process is complicated, and the network connection efficiency is reduced. And if a new connection protocol needs to be added subsequently, research and development personnel need to greatly change the original protocol connection code, the workload is large, a large amount of manpower is wasted, and the function expansion is not facilitated.
Disclosure of Invention
Aiming at the problems in the prior art, the embodiments of the present invention provide a network request connection method, device, medium and computer device, which are used to solve the technical problem in the prior art that when a network request is connected, the connection process is relatively complicated, and the connection efficiency is reduced.
The invention provides a network request connection method, which comprises the following steps:
creating a first protocol connection socket class and a second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: the method comprises the following steps of calling back an interface, an abstract interface with failed connection, an abstract interface with successful connection and an abstract interface with failed connection; the abstract interface which is failed to be connected inherits the connection failure notification interface, the abstract interface which is successfully connected inherits the connection success notification interface, and the abstract interface which is failed to be connected inherits the connection failure notification interface; the member variables include: a callback object corresponding to the callback interface, the first protocol socket class and an overtime timer;
when a network request is received, judging whether a client side for sending the network request has agent information or not, and if not, determining a short connection protocol used by the network request;
based on the short connection protocol, calling a corresponding protocol connection socket type by using the external connection interface, and establishing network request connection according to the corresponding protocol connection socket type.
Optionally, the creating a first protocol connection socket class and a second protocol connection socket class includes:
creating a base class of multi-system sockets;
creating the first protocol connection socket class, the first protocol connection socket class inheriting the base class;
creating the external connection interface in the first protocol connection socket class;
creating the second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class;
and setting a reload identifier in the second protocol connection socket class so as to reload the external connection interface by using the reload identifier when the short connection protocol of the network request is https protocol.
Optionally, the determining whether the client for sending the network request has proxy information includes:
when the application system of the client is an android system, judging whether a proxy IP and a proxy port number of the application system can be acquired or not in an abnormal acquisition mode;
and if the proxy IP and the proxy port number can be obtained, determining that the application system has the proxy information.
Optionally, the determining whether the client for sending the network request has proxy information includes:
when the application system of the client is the IOS system, calling an API function CFNetworkCopySystemProxySettings to acquire proxy setting information ProxySet of the IOS system;
judging whether agent information NSArray is existed in the agent setting information by using a reading function NSArray, proximity [ [ NSMakeCollectible ((NSArray) CFNetworkCopyProxiesForURL (url) (CFDictionRef) proxSet) ] auto element ]; the NSArray is an array used for storing the agent information, the NSMakeCollectable is a function interface of the reading function, the CFNetworkCopyProxies is the reading function, the url is a uniform resource locator of the network request, the CFDictionaryRef is a dictionary used for storing the agent setting information, and the autorelease is a resource release identifier;
and judging whether the NSArray proxies is empty or not, and if not, determining that the proxy information exists in the application system.
Optionally, after determining that the agent information exists in the application system, the method further includes:
reading the proxy IP by using a proxy IP reading function CFStringRef http _ proxy (CFStringRef) [ settings objects ForKey (NSString) < kCFProxHostNameKey ];
reading a proxy port number http _ port by using a port reading function CFNumberRef http _ port (CFNumberRef) [ settings objects ForKey (NSString) kCFProxPortNumberKey ]; the http _ proxy is the proxy IP, the objectForKey is a value-taking function, and the kcfproxyhost namekey is a Key value corresponding to the proxy information.
Optionally, determining the short connection protocol used by the network request includes:
acquiring a url address of the network request;
cutting the url to obtain prefix information of the url address;
determining a short connection protocol used by the network request based on the prefix information.
Optionally, after the network request connection is created according to the corresponding protocol connection socket class, the method further includes:
when the network request connection is successfully established, creating a session object, wherein the session object is used for carrying out data transceiving operation;
a timer for creating the session object;
and calling a transfer function move (socket _) to transfer the first protocol connection socket class and the second protocol connection socket class to the session object.
The present invention also provides a network requested connection device, which includes:
a creating unit, configured to create a first protocol connection socket class and a second protocol connection socket class, where the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: calling back an interface, an abstract interface with failed connection and an abstract interface with successful connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
the system comprises a judging unit, a sending unit and a receiving unit, wherein the judging unit is used for judging whether a client side used for sending a network request has proxy information or not when the network request is received, and if the client side does not have the proxy information, the judging unit determines a short connection protocol used by the network request;
and the calling unit is used for calling the corresponding protocol connection socket type by using the external connection interface based on the short connection protocol and establishing network request connection according to the corresponding protocol connection socket type.
The invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs any of the methods described above.
The invention also provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of any one of the above when executing the program.
The invention provides a network request connection method, a device, a medium and computer equipment, wherein the method comprises the following steps: creating a first protocol connection socket class and a second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface; creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface; creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: calling back an interface, an abstract interface with failed connection and an abstract interface with successful connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer; when a network request is received, judging whether a client side for sending the network request has agent information or not, and if not, determining a short connection protocol used by the network request; based on the short connection protocol, calling a corresponding protocol connection socket type by using the external connection interface, and establishing a network request connection according to the corresponding protocol connection socket type; therefore, socket classes supporting different protocols are created in advance, and a uniform external connection interface is created for the different socket classes, so that no matter what protocol is used by the network request, a caller only needs to call the external connection interface, the protocol used by the network request does not need to be determined firstly, and an interface corresponding to the protocol does not need to be searched, so that the connection process of the network request is obviously simplified, and the connection efficiency of the network request is ensured; even if a new protocol is subsequently added, developers do not need to change the existing framework, only need to re-create the corresponding socket class, and do not need to change the original protocol code and structure, thereby saving development resources and being more beneficial to function expansion.
Drawings
Fig. 1 is a schematic flow chart of a connection method of a network request according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a network requested connection device according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a network requested connected computer device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a network requested connected computer medium according to an embodiment of the present invention.
Detailed Description
In order to solve the technical problem that the connection efficiency is reduced due to the fact that the connection process is complicated when a network request is connected in the prior art, the invention provides a network request connection method, a network request connection device, a network request connection medium and computer equipment.
The technical solution of the present invention is further described in detail by the accompanying drawings and the specific embodiments.
Example one
The present embodiment provides a network request connection method, as shown in fig. 1, the method includes:
s110, creating a first protocol connection socket class and a second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
generally, when a network request is received, a network connection needs to be created based on a socket, and the socket needs to be abstracted in order to simplify the calling process of a caller. In this embodiment, because the sockets of the application systems are different, the iasync socket of the base class of the socket abstraction multi-system is used to create the cross-system socket, and the iasync socket may be for different application systems, so that the created cross-system socket may also be implemented for different application systems.
Based on the consideration of performance, more sockets are IO operations, not intensive computing types, and more sockets are read and written by IO devices, so that the IAsync socket is an asynchronous socket, and the cross-system implementation is realized based on asynchronous logic.
As an alternative embodiment, creating the first protocol connection socket class and the second protocol connection socket class includes:
creating a basic class IAsyncsocket of the multi-system socket;
creating a first protocol connection socket class, the first protocol connection socket class inherits the base class;
establishing an external connection interface in a first protocol connection socket class;
creating a second protocol connection socket class, the second protocol connection socket class inheriting the first protocol connection socket class; and setting a reload identifier in a second protocol connection socket class so as to reload the external connection interface by using the reload identifier when the short connection protocol of the network request is the https protocol.
The specific code is implemented as follows:
class ConAsyncSocket:virtual public IAsyncSocket{
virtual void connect (); external connection interface
}
Class ConAsyncSocketSsl:public IAsyncSocket{
virtual void connect () override; override is a heavy-duty identifier
}
Here, the first protocol connection socket class is conasync socket, and the second protocol connection socket class is conasync socket; since the conasync socket can also be inherited by other functions, in order to avoid that the subsequent extension of other functions also inherits the conasync socket, thereby generating a compilation error, a virtual legacy manner is adopted here.
The first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface; for example, the first protocol connection socket class may support the http protocol and the second protocol connection socket class may support the https protocol.
The first protocol connection socket class and the second protocol connection socket class are created in advance, and the first protocol connection socket class and the second protocol connection socket class have uniform external connection interfaces, so that a caller can call through the uniform external connection interfaces no matter what connection protocol needs to be called, the caller does not need to search a corresponding interface of a certain protocol, the calling process is simplified, and the calling efficiency is improved.
S111, creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, where the event notification interface includes: a connection failure notification interface and a connection success notification interface;
when each socket creates a connection, there may be a connection error (connection failure) and a connection success, and in order to feed back an event notification to a caller in time, an abstract interface class needs to be created, and a uniform event notification interface is created for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class. The event notification interface includes: a connection failure notification interface and a connection success notification interface. The code is implemented as follows:
class ConnectEvent { abstract interface class
public:
virtual-ConnectEvent () { } analytic interface
virtual void connectErr (const SocketException & ex) noexcept is 0; connection failure notification interface
virtual void connect success () nonexcess ═ 0; connection success notification interface
}
Here, the interface in the abstract interface class is a destruct interface, and when the object in the abstract interface class is released, memory leakage can be prevented. In addition, in order to increase the execution speed of the compiler, a keyword noexept is set in the connection failure notification interface and the connection success notification interface, and the keyword can ensure that the corresponding event can be executed quickly.
In addition, a description parameter const socket exception & ex is provided in the connection failure notification interface, and is used for describing the reason and the error type of the connection failure. The error type can be implemented by different error codes, and the error codes are added to the description parameters.
Therefore, the interface class comprises the connection failure notification interface and the connection success notification interface, so that the caller can be notified in time through the corresponding interface no matter the connection is successful or the connection is failed, and the caller can process the corresponding event in time.
S112, creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: the method comprises the following steps of calling back an interface, an abstract interface with failed connection, an abstract interface with successful connection and an abstract interface with failed connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
then, a connection class Connector needs to be created, and a corresponding interface and a member variable are created in the connection class; the connection class is used for providing time notification for the caller, so that the interface in the connection class needs to correspondingly inherit the interface in the abstract interface class. In this way, the connection layer of the connection class can be notified when the above-mentioned asynchronous socket has an event notification.
After the connection class is established, establishing corresponding interfaces and member variables in the connection class; the interface includes: calling back an interface, an abstract interface which is successfully connected and an abstract interface which is failed to be connected; the abstract interface which is successfully connected inherits the connection success notification interface, and the abstract interface which is failed to be connected inherits the connection failure notification interface; the member variables include: a callback object corresponding to the callback interface, a first protocol socket class and an overtime timer. The code created by each interface is implemented as follows:
class Connector protected ConAsyncSocket::ConnectEvent
class Callback { Callback interface
virtual~Callback(){}
virtual void connected error (const SocketException & ex) is 0; abstract interface for connection failure
virtual void connected success (Session) ═ 0; successfully connected abstract interface
}
For the same reason, each interface in the connection class is also a destruct interface, and when the object in the connection class is released, memory leakage can be prevented. The description parameter socketException & ex in the abstract interface with connection failure and the description parameter const socketException & ex in the connection error interface have the same function. The abstract interface which is successfully connected comprises a Session parameter Session, and when the connection is successfully established, the parameter is used for realizing subsequent data transceiving operation.
After each interface is created, member variables are created in the connection class. The code is implemented as follows:
callback cb _; callback object
Timer timeout _; overtime timer
unique _ ptr < ConAsyncSocket > socket _; first protocol sockets class
Connector (Callback, Timer timeout); constructor of connection class, initializing member variables
:cb_(CHECK_NOTNULL(callback)),timeout_(timeout){}
Here, the conasync socket is encapsulated with uique _ ptr, indicating that here the entire connection has only this one asynchronous conasync socket. And one network request corresponds to one ConAsyncSocket, and the unique _ ptr can be used for ensuring that if some ConAsyncSocks are not accessed in the whole network connection process, automatic release can be carried out, so that resources are prevented from being leaked.
For the constructor of the connection class, the constructor comprises two parameters, wherein the first parameter is a member variable callback, the second parameter is timeout, and the timeout is used for controlling the timeout of the connection, so that the phenomenon that the whole connection process is too long due to an IO event and the phenomenon of blocking is avoided.
For example, the timeout may be 5s, and if no connection success or connection failure event occurs after 5 seconds, the connection may be timed out, the current connection is exited, and the reason of the current error is given as the timeout reason through the abstraction interface with the connection failure.
Here, when a connection has an error, in order to ensure that a developer can quickly find a reason, it is necessary to ensure that the callback object callback cannot be empty, so that when assigning a callback, CHECK _ notify is used to CHECK an incoming callback pointer in the callback object, so that once the incoming pointer is empty, an error can be immediately reported.
Specifically, when an error is reported, the ConAsyncSocket sends the event notification of the connection failure to the connection class, and the connection class forwards the event notification to the caller.
After error reporting, the corresponding current conasync socket cannot be used continuously, and in order to avoid that a developer uses the current conasync socket again due to misoperation, the method further comprises the following steps: and emptying the current ConAsyncSocket which is reported to be wrong.
The specific connection of the protocol is realized by setting the connection class, and each abstract interface in the connection class inherits the corresponding interface in the interface class, so that the network request can be smoothly connected.
S113, when receiving a network request, judging whether a client used for sending the network request has agent information, if not, determining a short connection protocol used by the network request;
when a network request is received, whether proxy information exists in a client side used for sending the network request needs to be judged, if yes, the network request is determined to use a proxy mode for connection, and if not, a short connection protocol used by the network request is determined to be connected.
As an optional embodiment, determining whether proxy information exists in a client for sending the network request includes:
when the application system of the client is an android system, judging whether a proxy IP and a proxy port number of the application system can be acquired or not in an abnormal acquisition mode;
if the proxy IP and the proxy port number can be obtained, determining that the application system has proxy information; the network requests the connection in proxy mode.
It should be noted that if there is a compatibility problem, it may also result in that the proxy IP and the proxy port number may not be obtained, and then it needs to be obtained by reading information of the application system, and if the proxy IP and the proxy port number are not obtained, it indicates that the application system does not set the proxy.
The specific code is implemented as follows:
try{
proxyIp ═ proxy. getdefaulthost (); obtaining proxy ip
proxyPort (); obtaining a proxy port number
Getproperty ("http.proxyhost"); reading system information
proxyPort ═ system.getproperty ("http.proxyport"); reading system information
}catch(final Exception e){
Printstacktrace (); printing current call stack information
}
Further, if the acquisition exception occurs, the current call stack information is printed, and the url of the current network request is printed at the same time, so that the url with the exception can be positioned.
As an alternative embodiment, the determining whether proxy information exists for the client of the network request includes:
when the application system of the client is the IOS system, calling an API function CFNetworkCopySystemProxySettings to acquire proxy setting information ProxySet of the IOS system; the code is implemented as follows:
NSDictionary, proxySet, [ NSMakeCollectable ((NSDictionary) cfnetworkcopy system proxysettings ()) autorelease ]; the NSMakeCollectible is a calling interface of the API function, and the autorelease is a resource release identifier; NSDictionary is a dictionary for storing proxy setting information ProxySet;
judging whether agent information NSArray parameters exists in the agent setting information by using a read function NSArray parameters ═[ NSMakeCollectable ((NSArray) cfnetworkcopyproxiforurl (url, (cfdictionary) proxySet)) autoreace ]; NSArray is an array used for storing agent information, NSMakeCollectible is a function interface of a reading function, CFNetworkcopyProxes is the reading function, url is a uniform resource locator of the network request, CFDictionaryRef is a dictionary used for storing agent setting information, and autorelease is a resource release identifier;
and judging whether NSArray proxies is empty or not, and if not, determining that the proxy information exists in the application system.
As an optional embodiment, after determining that the proxy information exists in the application system, the method further includes:
reading the proxy IP by using a proxy IP reading function CFStringRef http _ proxy (CFStringRef) [ settings objects ForKey (NSString) < kCFProxHostNameKey ];
reading a proxy port number http _ port by using a port reading function CFNumberRef http _ port (CFNumberRef) [ settings objects ForKey (NSString) kCFProxPortNumberKey ]; the http _ proxy is an agent IP, the objectForKey is a value-taking function, and the kCFProxyHostNameKey is a Key value corresponding to the agent information.
As an optional embodiment, if the proxy information is not obtained in any of the above manners, it indicates that the network request is connected using the short connection protocol.
Because the short connection protocol includes http protocol, https protocol, and the like, when it is determined that the network request is connected using the short connection protocol, it is necessary to determine which protocol the short connection protocol is.
As an alternative embodiment, determining the short connection protocol used by the network request includes:
acquiring a url address of a network request;
cutting the url to obtain prefix information of the url address;
and judging the short connection protocol used by the network request based on the prefix information.
For example, if the prefix is Http, it indicates an Http protocol, and if the prefix is Https, it identifies an Http protocol.
Therefore, after the network request is received, the connection protocol used by the network request is determined, and the corresponding connection protocol is conveniently and quickly called subsequently.
S114, based on the short connection protocol, calling a corresponding protocol connection socket class by using the external connection interface, and creating a network request connection according to the corresponding protocol connection socket class.
After the short connection protocol used by the network request is determined, the corresponding protocol connection socket class is called by using the external connection interface based on the short connection protocol, and the network request connection is established according to the corresponding protocol connection socket class.
For example, if the short connection protocol is http protocol, then ConAsyncSocket connects. If the short connection protocol is https protocol, then ConAsyncSocketSsl is used for the connection. If the proxy mode is adopted, after the ConAsyncSocket of the http protocol is used for connection successfully, ssl protocol verification is carried out on the basis, and a connection success event is called back after the verification is successful. The specific code is implemented as follows:
ConAsyncSocket*socket;
if(http){
socket_=new ConAsyncSocket();
}else{
if(proxy&&proxyPort){socket_=new ConAsyncSocket();
}else{
socket_=new ConAsyncSocketSsl();
}
}
when the connection is successful, the event notification of the successful connection needs to be forwarded to the caller through the connectinsuccess abstract interface, and since the connectinsuccess abstract interface is a connection success notification interface in the inheritance abstract interface class, the method for realizing the inherited class definitely needs to use the overload identification override.
When the network request connection is successfully established, a session object is established, and the session object is used for carrying out data transceiving operation;
a timer for creating a session object;
and calling a transfer function move to transfer the first protocol connection socket class and the second protocol connection socket class to the session object. In this way, in the subsequent data transceiving operation, the session object manages the first protocol connection socket class and the second protocol connection socket class, and data transceiving is realized. The specific code is implemented as follows:
session ═ new Session (timeout, move), Session is set; timer for timeout being session object
And the timer of the session object is used for monitoring whether the data receiving and sending is overtime so as to carry out subsequent processing procedures. For example, sending data over time, requiring a developer to further check the cause of the time-out, etc.
Therefore, no matter what protocol is used by the network request, the corresponding socket type can be called through the unified external connection interface set by the application to realize the establishment of the network connection, the connection flow is simplified, and the connection efficiency is improved.
The network request connection method provided by the embodiment can bring at least the following beneficial effects:
the method comprises the steps that socket types supporting different protocols are created in advance, and a uniform external connection interface is created for the different socket types, so that no matter what protocol is used by a network request, a caller only needs to call the external connection interface, the protocol used by the network request does not need to be determined, and an interface corresponding to the protocol does not need to be searched, so that the connection process of the network request is obviously simplified, and the connection efficiency of the network request is ensured; even if a new protocol is subsequently added, developers do not need to change the existing framework, only need to re-create the corresponding socket class, and do not need to change the original protocol code and structure, thereby saving development resources and being more beneficial to function expansion.
Based on the same inventive concept, the application also provides a network requested connection device, which is detailed in embodiment two.
Example two
The present embodiment provides a network requested connection apparatus, as shown in fig. 2, the apparatus includes: a creating unit 21, a judging unit 22 and a calling unit 23; wherein the content of the first and second substances,
a creating unit 21, configured to create a first protocol connection socket class and a second protocol connection socket class, where the first protocol connection socket class supports an http protocol; the second protocol connection socket class inherits the first protocol connection socket class, the second multi-protocol connection socket class supporting https protocol; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface; creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface; creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: calling back an interface, an abstract interface with failed connection and an abstract interface with successful connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
a determining unit 22, configured to determine, when a network request is received, whether proxy information exists in a client that is used to send the network request, and if the proxy information does not exist, determine a short connection protocol used by the network request;
a calling unit 23, configured to call, based on the short connection protocol, a corresponding protocol connection socket class by using the external connection interface, and create a network request connection according to the corresponding protocol connection socket class.
Specifically, generally, when a network request is received, a network connection needs to be created based on a socket, and the socket needs to be abstracted in order to simplify the calling process of a caller. In this embodiment, because the sockets of the application systems are different, the sockets of the cross-system are created by using the iasync socket, which is a basic class of the socket abstraction multi-system, and the created cross-system sockets can also be implemented for different application systems because the iasync socket can be for different application systems.
Based on the consideration of performance, more sockets are IO operations, not intensive computing types, and more sockets are read and written by IO devices, so that the IAsync socket is an asynchronous socket, and the cross-system implementation is realized based on asynchronous logic.
As an optional embodiment, the creating unit 21 is specifically configured to:
creating a basic class IAsyncsocket of the multi-system socket;
creating a first protocol connection socket class, the first protocol connection socket class inherits the base class;
establishing an external connection interface in a first protocol connection socket class;
creating a second protocol connection socket class, the second protocol connection socket class inheriting the first protocol connection socket class; and setting a reload identifier in a second protocol connection socket class so as to reload the external connection interface by using the reload identifier when the short connection protocol of the network request is the https protocol.
The specific code is implemented as follows:
class ConAsyncSocket:virtual public IAsyncSocket{
virtual void connect (); external connection interface
}
Class ConAsyncSocketSsl:public IAsyncSocket{
virtual void connect () override; override is a heavy-duty identifier
}
Here, the first protocol connection socket class is conasync socket, and the second protocol connection socket class is conasync socket; since the conasync socket can also be inherited by other functions, in order to avoid that the subsequent extension of other functions also inherits the conasync socket, thereby generating a compilation error, a virtual legacy manner is adopted here.
The first and second multi-protocol connection sockets support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface; for example, the first protocol connection socket class may support the http protocol and the second protocol connection socket class may support the https protocol.
The first protocol connection socket class and the second protocol connection socket class are created in advance, and the first protocol connection socket class and the second protocol connection socket class have uniform external connection interfaces, so that a caller can call through the uniform external connection interfaces no matter what connection protocol needs to be called, the caller does not need to search a corresponding interface of a certain protocol, the calling process is simplified, and the calling efficiency is improved.
When creating a connection, each socket may have a connection error (connection failure) and a connection success, and in order to feed back an event notification to a caller in time, the creating unit 21 needs to create an abstract interface class, and create a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class. The event notification interface includes: a connection failure notification interface and a connection success notification interface. The code is implemented as follows:
class ConnectEvent { abstract interface class
public:
virtual-ConnectEvent () { } analytic interface
virtual void connectErr (const SocketException & ex) noexcept is 0; connection failure notification interface
virtual void connect success () nonexcess ═ 0; connection success notification interface
}
Here, the interface in the abstract interface class is a destruct interface, and when the object in the abstract interface class is released, memory leakage can be prevented. In addition, in order to increase the execution speed of the compiler, a keyword noexept is set in the connection failure notification interface and the connection success notification interface, and the keyword can ensure that the corresponding event can be executed quickly.
In addition, a description parameter const socket exception & ex is provided in the connection failure notification interface, and is used for describing the reason and the error type of the connection failure. The error type can be implemented by different error codes, and the error codes are added to the description parameters.
Therefore, the interface class comprises the connection failure notification interface and the connection success notification interface, so that the caller can be notified in time through the corresponding interface no matter the connection is successful or the connection is failed, and the caller can process the corresponding event in time.
Then, the creating unit 21 needs to create a connection class Connector, and create a corresponding interface and a member variable in the connection class; the connection class is used for providing time notification for the caller, so that the interface in the connection class needs to correspondingly inherit the interface in the abstract interface class. In this way, the connection layer of the connection class can be notified when the above-mentioned asynchronous socket has an event notification.
After the connection class is established, establishing corresponding interfaces and member variables in the connection class; the interface includes: calling back an interface, an abstract interface which is successfully connected and an abstract interface which is failed to be connected; the abstract interface which is successfully connected inherits the connection success notification interface, and the abstract interface which is failed to be connected inherits the connection failure notification interface; the member variables include: a callback object corresponding to the callback interface, a first protocol socket class and an overtime timer. The code created by each interface is implemented as follows:
class Connector protected ConAsyncSocket::ConnectEvent
class Callback { Callback interface
virtual~Callback(){}
virtual void connected error (const SocketException & ex) is 0; abstract interface for connection failure
virtual void connected success (Session) ═ 0; successfully connected abstract interface
}
For the same reason, each interface in the connection class is also a destruct interface, and when the object in the connection class is released, memory leakage can be prevented. The description parameter socketException & ex in the abstract interface with connection failure and the description parameter const socketException & ex in the connection error interface have the same function. The abstract interface which is successfully connected comprises a Session parameter Session, and when the connection is successfully established, the parameter is used for realizing subsequent data transceiving operation.
After each interface is created, member variables are created in the connection class. The code is implemented as follows:
callback cb _; callback object
Timer timeout _; overtime timer
unique _ ptr < ConAsyncSocket > socket _; first protocol sockets class
Connector (Callback, Timer timeout); constructor of connection class, initializing member variables
:cb_(CHECK_NOTNULL(callback)),timeout_(timeout){}
Here, the conasync socket is encapsulated with uique _ ptr, indicating that here the entire connection has only this one asynchronous conasync socket. And one network request corresponds to one ConAsyncSocket, and the unique _ ptr can be used for ensuring that if some ConAsyncSocks are not accessed in the whole network connection process, automatic release can be carried out, so that resources are prevented from being leaked.
For the constructor of the connection class, the constructor comprises two parameters, wherein the first parameter is a member variable callback, the second parameter is timeout, and the timeout is used for controlling the timeout of the connection, so that the phenomenon that the whole connection process is too long due to an IO event and the phenomenon of blocking is avoided.
For example, the timeout may be 5s, and if no connection success or connection failure event occurs after 5 seconds, the connection may be timed out, the current connection is exited, and the reason of the current error is given as the timeout reason through the abstraction interface with the connection failure.
Here, when a connection has an error, in order to ensure that a developer can quickly find a reason, it is necessary to ensure that the callback object callback cannot be empty, so that when assigning a callback, CHECK _ notify is used to CHECK an incoming callback pointer in the callback object, so that once the incoming pointer is empty, an error can be immediately reported.
Specifically, when an error is reported, the ConAsyncSocket sends the event notification of the connection failure to the connection class, and the connection class forwards the event notification to the caller.
After error reporting, the corresponding current conasync socket cannot be used continuously, and in order to avoid that a developer uses the current conasync socket again due to misoperation, the method further comprises the following steps: and emptying the current ConAsyncSocket which is reported to be wrong.
The specific connection of the protocol is realized by setting the connection class, and each abstract interface in the connection class inherits the corresponding interface in the interface class, so that the network request can be smoothly connected.
When receiving the network request, the determining unit 22 needs to determine whether proxy information exists in the client for sending the network request, if so, determine that the network request uses a proxy mode for connection, and if not, determine that the network request uses a short connection protocol for connection.
As an alternative embodiment, the determining unit 22 is specifically configured to:
when the application system of the client is an android system, judging whether a proxy IP and a proxy port number of the application system can be acquired or not in an abnormal acquisition mode;
if the proxy IP and the proxy port number can be obtained, determining that the application system has proxy information; the network requests the connection in proxy mode.
It should be noted that if there is a compatibility problem, it may also result in that the proxy IP and the proxy port number may not be obtained, and then it needs to be obtained by reading information of the application system, and if the proxy IP and the proxy port number are not obtained, it indicates that the application system does not set the proxy.
The specific code is implemented as follows:
try{
proxyIp ═ proxy. getdefaulthost (); obtaining proxy ip
proxyPort (); obtaining a proxy port number
Getproperty ("http.proxyhost"); reading system information
proxyPort ═ system.getproperty ("http.proxyport"); reading system information
}catch(final Exception e){
Printstacktrace (); printing current call stack information
}
Further, if the acquisition exception occurs, the current call stack information is printed, and the url of the current network request is printed at the same time, so that the url with the exception can be positioned.
As an alternative embodiment, the determining unit 22 is specifically configured to:
when the application system of the client is the IOS system, calling an API function CFNetworkCopySystemProxySettings to acquire proxy setting information ProxySet of the IOS system; the code is implemented as follows:
NSDictionary, proxySet, [ NSMakeCollectable ((NSDictionary) cfnetworkcopy system proxysettings ()) autorelease ]; the NSMakeCollectible is a calling interface of the API function, and the autorelease is a resource release identifier; NSDictionary is a dictionary for storing proxy setting information ProxySet;
judging whether agent information NSArray is present in the agent setting information by using a reading function NSArray, proximity [ [ NSMakeCollectible ((NSArray) CFNetworkCopyProxiesForURL (url) (CFDictionaryRef) proxSet) ] autorelease ]; NSArray is an array used for storing agent information, NSMakeCollectible is a function interface of a reading function, CFNetworkcopyProxes is the reading function, url is a uniform resource locator of the network request, CFDictionaryRef is a dictionary used for storing agent setting information, and autorelease is a resource release identifier;
and judging whether NSArray proxies is empty or not, and if not, determining that the proxy information exists in the application system.
As an optional embodiment, after determining that the proxy information exists in the application system, the determining unit 22 is further configured to:
reading the proxy IP by using a proxy IP reading function CFStringRef http _ proxy (CFStringRef) [ settings objects ForKey (NSString) < kCFProxHostNameKey ];
reading a proxy port number http _ port by using a port reading function CFNumberRef http _ port (CFNumberRef) [ settings objects ForKey (NSString) kCFProxPortNumberKey ]; the http _ proxy is an agent IP, the objectForKey is a value-taking function, and the kCFProxyHostNameKey is a Key value corresponding to the agent information.
As an alternative embodiment, if the proxy information is not obtained in any of the above manners, it indicates that the network request is connected using the short connection protocol.
Because the short connection protocol includes http protocol, https protocol, and the like, when it is determined that the network request is connected using the short connection protocol, it is necessary to determine which protocol the short connection protocol is.
As an alternative embodiment, the determining unit 22 determines the short connection protocol used by the network request, including:
acquiring a url address of a network request;
cutting the url to obtain prefix information of the url address;
and judging the short connection protocol used by the network request based on the prefix information.
For example, if the prefix is Http, it indicates an Http protocol, and if the prefix is Https, it identifies an Http protocol.
Therefore, after the network request is received, the connection protocol used by the network request is determined, and the corresponding connection protocol is conveniently and quickly called subsequently.
After determining the short connection protocol used by the network request, the calling unit 23 calls the corresponding protocol connection socket class by using the external connection interface based on the short connection protocol, and creates a network request connection according to the corresponding protocol connection socket class.
For example, if the short connection protocol is http protocol, then ConAsyncSocket connects. If the short connection protocol is https protocol, then ConAsyncSocketSsl is used for the connection. If the proxy mode is adopted, after the ConAsyncSocket of the http protocol is used for connection successfully, ssl protocol verification is carried out on the basis, and after the verification is successful, a connection success event is called back. The specific code is implemented as follows:
ConAsyncSocket*socket;
if(http){
socket_=new ConAsyncSocket();
}else{
if(proxy&&proxyPort){socket_=new ConAsyncSocket();
}else{
socket_=new ConAsyncSocketSsl();
}
}
when the connection is successful, the event notification of the successful connection needs to be forwarded to the caller through the connectinsuccess abstract interface, and since the connectinsuccess abstract interface is a connection success notification interface in the inheritance abstract interface class, the method for realizing the inherited class definitely needs to use the overload identification override.
And when it is determined that the network request connection establishment is successful, the creating unit 21 is further configured to:
creating a session object, wherein the session object is used for carrying out data transceiving operation;
a timer for creating a session object;
and calling a transfer function move (socket _) to transfer the first protocol connection socket class and the second protocol connection socket class to the session object. In this way, in the subsequent data transceiving operation, the session object manages the first protocol connection socket class and the second protocol connection socket class, and data transceiving is realized. The specific code is implemented as follows:
session ═ new Session (timeout, move), Session is set; timer for timeout being session object
And the timer of the session object is used for monitoring whether the data receiving and sending is overtime so as to carry out subsequent processing procedures. For example, sending data over time, requiring a developer to further check the cause of the time-out, etc.
Therefore, no matter what protocol is used by the network request, the corresponding socket type can be called through the unified external connection interface set by the application to realize the establishment of the network connection, the connection flow is simplified, and the connection efficiency is improved.
The network request connection method and device provided by the embodiment of the invention have the beneficial effects that at least:
the invention provides a network request connection method, a device, a medium and computer equipment, wherein the method comprises the following steps: creating a first protocol connection socket class and a second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface; creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface; creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: calling back an interface, an abstract interface with failed connection and an abstract interface with successful connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer; when a network request is received, judging whether a client side for sending the network request has agent information or not, and if not, determining a short connection protocol used by the network request; based on the short connection protocol, calling a corresponding protocol connection socket class by using the external connection interface, and establishing a network request connection according to the corresponding protocol connection socket class; therefore, socket classes supporting different protocols are created in advance, and a uniform external connection interface is created for the different socket classes, so that no matter what protocol is used by the network request, a caller only needs to call the external connection interface, the protocol used by the network request does not need to be determined firstly, and an interface corresponding to the protocol does not need to be searched, so that the connection process of the network request is obviously simplified, and the connection efficiency of the network request is ensured; even if a new protocol is subsequently added, developers do not need to change the existing framework, only need to re-create the corresponding socket class, and do not need to change the original protocol code and structure, thereby saving development resources and being more beneficial to function expansion.
Based on the same inventive concept, the invention also provides computer equipment, which is detailed in the third embodiment.
EXAMPLE III
The present embodiment provides a computer apparatus, as shown in fig. 3, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320, where the processor 320 executes the computer program 311 to implement the following steps:
creating a first protocol connection socket class and a second protocol connection socket class, wherein the first protocol connection socket class supports an http protocol; the second protocol connection socket class inherits the first protocol connection socket class, the second multi-protocol connection socket class supporting https protocol; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: the method comprises the following steps of calling back an interface, an abstract interface with failed connection, an abstract interface with successful connection and an abstract interface with failed connection; the abstract interface which fails to be connected inherits the connection failure notification interface, the abstract interface which succeeds in being connected inherits the connection success notification interface, and the abstract interface which fails to be connected inherits the connection failure notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
when a network request is received, judging whether proxy information exists in a client side for sending the network request, and if the proxy information does not exist in the client side, determining a short connection protocol used by the network request;
based on the short connection protocol, calling a corresponding protocol connection socket type by using the external connection interface, and establishing a network request connection according to the corresponding protocol connection socket type.
In particular, when the processor 320 executes the computer program 311, any one of the first embodiment can be implemented.
Since the computer device described in this embodiment is a device used for implementing a network requested connection method in the first embodiment of the present application, a person skilled in the art can understand a specific implementation manner of the computer device of this embodiment and various variations thereof based on the method described in the first embodiment of the present application, and therefore, how to implement the method in the embodiment of the present application by the server is not described in detail herein. The equipment used by those skilled in the art to implement the methods in the embodiments of the present application is within the scope of the present application.
Based on the same inventive concept, the application provides a storage medium corresponding to the fourth embodiment, which is described in detail in the fourth embodiment.
Example four
The present embodiment provides a computer-readable storage medium 400, as shown in fig. 4, on which a computer program 411 is stored, which computer program 411, when being executed by a processor, realizes the steps of:
creating a first protocol connection socket class and a second protocol connection socket class, wherein the first protocol connection socket class supports an http protocol; the second protocol connection socket class inherits the first protocol connection socket class, the second multi-protocol connection socket class supporting https protocol; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, where the event notification interface includes: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: the method comprises the following steps of calling back an interface, an abstract interface with failed connection, an abstract interface with successful connection and an abstract interface with failed connection; the abstract interface which fails to be connected inherits the connection failure notification interface, the abstract interface which succeeds in being connected inherits the connection success notification interface, and the abstract interface which fails to be connected inherits the connection failure notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
when a network request is received, judging whether a client side for sending the network request has agent information or not, and if not, determining a short connection protocol used by the network request;
based on the short connection protocol, calling a corresponding protocol connection socket type by using the external connection interface, and establishing network request connection according to the corresponding protocol connection socket type.
In a specific implementation, when the computer program 411 is executed by a processor, any one of the first embodiment may be implemented.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
The above description is only exemplary of the present invention and should not be taken as limiting the scope of the present invention, and any modifications, equivalents, improvements, etc. that are within the spirit and principle of the present invention should be included in the present invention.

Claims (10)

1. A network requested connection method, the method comprising:
creating a first protocol connection socket class and a second protocol connection socket class, wherein the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: the method comprises the following steps of calling back an interface, an abstract interface with failed connection, an abstract interface with successful connection and an abstract interface with failed connection; the abstract interface which is failed to be connected inherits the connection failure notification interface, the abstract interface which is successfully connected inherits the connection success notification interface, and the abstract interface which is failed to be connected inherits the connection failure notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
when a network request is received, judging whether a client side for sending the network request has agent information or not, and if not, determining a short connection protocol used by the network request;
based on the short connection protocol, calling a corresponding protocol connection socket type by using the external connection interface, and establishing network request connection according to the corresponding protocol connection socket type.
2. The method of claim 1, wherein creating the first and second classes of protocol connection sockets comprises:
creating a base class of multi-system sockets;
creating the first protocol connection socket class, the first protocol connection socket class inheriting the base class;
creating the external connection interface in the first protocol connection socket class;
creating the second protocol connection socket class, the second protocol connection socket class inheriting the first protocol connection socket class;
and setting a reload identifier in the second protocol connection socket class so as to reload the external connection interface by using the reload identifier when the short connection protocol of the network request is https protocol.
3. The method of claim 1, wherein the determining whether proxy information exists for a client sending the network request comprises:
when the application system of the client is an android system, judging whether a proxy IP and a proxy port number of the application system can be acquired or not in an abnormal acquisition mode;
and if the proxy IP and the proxy port number can be obtained, determining that the application system has the proxy information.
4. The method of claim 1, wherein the determining whether proxy information exists for a client sending the network request comprises:
when the application system of the client is the IOS system, calling an API function CFNetworkCopySystemProxySettings to acquire proxy setting information ProxySet of the IOS system;
judging whether agent information NSArray is existed in the agent setting information by using a reading function NSArray, proximity [ [ NSMakeCollectible ((NSArray) CFNetworkCopyProxiesForURL (url) (CFDictionRef) proxSet) ] auto element ]; the NSArray is an array used for storing the agent information, the NSMakeCollectible is a function interface of the read function, the CFNetworkcopyProxes is the read function, the url is a uniform resource locator of the network request, the CFDictionaryRef is a dictionary used for storing the agent setting information, and the autorelease is a resource release identifier;
and judging whether the NSArray proxies is empty or not, and if not, determining that the proxy information exists in the application system.
5. The method of claim 4, wherein after determining that the proxy information exists for the application system, further comprising:
reading the proxy IP by using a proxy IP reading function CFStringRef http _ proxy (CFStringRef) [ settings objects ForKey (NSString) < kCFProxHostNameKey ];
reading a proxy port number http _ port by using a port reading function CFNumberRef http _ port (CFNumberRef) [ settings objects ForKey (NSString) kCFProxPortNumberKey ]; the http _ proxy is the proxy IP, the objectForKey is a value-taking function, and the kcfproxyhost namekey is a Key value corresponding to the proxy information.
6. The method of claim 1, wherein determining the short-connection protocol used by the network request comprises:
acquiring a url address of the network request;
cutting the url to obtain prefix information of the url address;
determining a short connection protocol used by the network request based on the prefix information.
7. The method of claim 1, wherein the creating a network requested connection according to the corresponding protocol connection socket class further comprises:
when the network request connection is successfully established, creating a session object, wherein the session object is used for carrying out data transceiving operation;
a timer for creating the session object;
and calling a transfer function move (socket _) to transfer the first protocol connection socket class and the second protocol connection socket class to the session object.
8. An apparatus for network requested connection, the apparatus comprising:
a creating unit, configured to create a first protocol connection socket class and a second protocol connection socket class, where the second protocol connection socket class inherits the first protocol connection socket class, and the first protocol connection socket class and the second multi-protocol connection socket class support different short connection protocols; the first protocol connection socket class and the second protocol connection socket class have a uniform external connection interface;
creating an abstract interface class, and creating a uniform event notification interface for the first protocol connection socket class and the second protocol connection socket class in the abstract interface class, wherein the event notification interface comprises: a connection failure notification interface and a connection success notification interface;
creating a connection class, and creating a corresponding interface and a member variable in the connection class; the interface includes: calling back an interface, an abstract interface with failed connection and an abstract interface with successful connection; the abstract interface which is failed to connect inherits the connection failure notification interface, and the abstract interface which is successfully connected inherits the connection success notification interface; the member variables include: the callback object corresponding to the callback interface, the first protocol socket class and the timeout timer;
the system comprises a judging unit and a sending unit, wherein the judging unit is used for judging whether proxy information exists in a client side for sending a network request when the network request is received, and if the proxy information does not exist in the client side, determining a short connection protocol used by the network request;
and the calling unit is used for calling the corresponding protocol connection socket type by using the external connection interface based on the short connection protocol and establishing network request connection according to the corresponding protocol connection socket type.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, is adapted to carry out the method of any one of claims 1 to 7.
10. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of any of claims 1 to 7 when executing the program.
CN202011157709.4A 2020-10-26 2020-10-26 Network request connection method, device, medium and computer equipment Pending CN114500681A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011157709.4A CN114500681A (en) 2020-10-26 2020-10-26 Network request connection method, device, medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011157709.4A CN114500681A (en) 2020-10-26 2020-10-26 Network request connection method, device, medium and computer equipment

Publications (1)

Publication Number Publication Date
CN114500681A true CN114500681A (en) 2022-05-13

Family

ID=81471238

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011157709.4A Pending CN114500681A (en) 2020-10-26 2020-10-26 Network request connection method, device, medium and computer equipment

Country Status (1)

Country Link
CN (1) CN114500681A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050251856A1 (en) * 2004-03-11 2005-11-10 Aep Networks Network access using multiple authentication realms
US7768939B1 (en) * 2007-01-02 2010-08-03 Juniper Networks, Inc. Network proxy with asymmetric connection connectivity
CN107222479A (en) * 2017-05-27 2017-09-29 武汉斗鱼网络科技有限公司 Communication security strengthens method, device, communication means and user terminal
CN108234149A (en) * 2016-12-09 2018-06-29 沈阳美行科技有限公司 Network request management method and device
CN109889911A (en) * 2019-03-26 2019-06-14 南京海比信息技术有限公司 The method that a port carries multiple stream protocols is realized in Streaming Media reverse proxy service

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050251856A1 (en) * 2004-03-11 2005-11-10 Aep Networks Network access using multiple authentication realms
US7768939B1 (en) * 2007-01-02 2010-08-03 Juniper Networks, Inc. Network proxy with asymmetric connection connectivity
CN108234149A (en) * 2016-12-09 2018-06-29 沈阳美行科技有限公司 Network request management method and device
CN107222479A (en) * 2017-05-27 2017-09-29 武汉斗鱼网络科技有限公司 Communication security strengthens method, device, communication means and user terminal
CN109889911A (en) * 2019-03-26 2019-06-14 南京海比信息技术有限公司 The method that a port carries multiple stream protocols is realized in Streaming Media reverse proxy service

Similar Documents

Publication Publication Date Title
WO2019184164A1 (en) Method for automatically deploying kubernetes worker node, device, terminal apparatus, and readable storage medium
CN113630372A (en) Cloud edge coordination system for edge computing
US7516178B1 (en) Communicating messages between components in a client/server environment using a object broker
US20030037289A1 (en) Fault tolerance software system with periodic external self-test failure detection
AU2002337927A1 (en) A generic connector between vitria and an EJB compliant API for an application
EP1440367A1 (en) A generic connector between vitria and an ejb compliant api for an application
CN112422681B (en) Cross-platform distributed communication calling method and device
CN111597061A (en) Method and device for remote procedure call of client or server
KR20130108613A (en) Method and device for interprocess communication and computer storage medium
CN112953983A (en) SFTP transmission method and device
CN111143034A (en) Method, device and system for controlling network data forwarding plane
US7043726B2 (en) Binding of processes in network systems
CN108234174B (en) Management method and device of virtual network function
CN104570967B (en) Long-range control method and system based on android system
CN117194064A (en) Remote calling method and device
CN112256351A (en) Implementation method of Feign component, micro-service calling method and device
CN114500681A (en) Network request connection method, device, medium and computer equipment
US7805733B2 (en) Software implementation of hardware platform interface
US20100070552A1 (en) Providing a Socket Connection between a Java Server and a Host Environment
Dake et al. The corosync cluster engine
CN111031123B (en) Spark task submission method, system, client and server
CN114489847A (en) Method, system, device and storage medium for managing and controlling process manager
Cisco Troubleshooting SNA View on the Workstation
Cisco Troubleshooting SNA View on the Workstation
CN112130900A (en) User information management method, system, equipment and medium for BMC

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination