Disclosure of Invention
The present invention has been made in view of the above problems, and it is an object of the present invention to provide a method and apparatus for accessing services, which overcome or at least partially solve the above problems, and which solve the problems of the prior art, such as the inefficiency of the prior art.
According to a first aspect of the present invention, there is provided a method of accessing a service, comprising:
the method comprises the steps that a first terminal establishes a tunnel capable of communicating with a second terminal;
the first terminal sends a service access request to the second terminal through the tunnel, wherein the service access request adopts a Transmission Control Protocol (TCP) and/or a User Datagram Protocol (UDP);
and the first terminal receives a service access response sent by the second terminal through the tunnel, and executes related operation according to the service access response, wherein the service access response adopts the TCP and/or UDP protocol.
In an embodiment, according to the method in the above embodiment of the present invention, the sending, by the first terminal, a service access request to the second terminal through the tunnel includes:
the application layer of the first terminal and the tunnel layer of the first terminal establish TCP connection;
a tunnel layer of the first terminal determines a TCP service request port;
the application layer of the first terminal sends the service access request to the tunnel layer of the first terminal through the TCP connection;
and the tunnel layer of the first terminal sends the service access request to the tunnel layer of the second terminal from the TCP service request port.
In some embodiments, according to the method of any one of the above embodiments of the present invention, a protocol used by the TCP service request port is the same as a protocol used by the service providing port in the second terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the port number of the TCP service request port and the port number of the service providing port in the second terminal are the same or different.
In some embodiments, according to the method in any one of the above embodiments of the present invention, after the application layer of the first terminal establishes a TCP connection with the tunnel layer of the first terminal, before the first terminal receives a service access response sent by the second terminal through the tunnel, the method further includes:
and the tunnel layer of the first terminal sends the TCP connection identifier and/or the port number of the TCP service request port to the tunnel layer of the second terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the sending, by the first terminal, a service access request to the second terminal through the tunnel includes:
a tunnel layer of the first terminal determines a UDP service request port;
the application layer of the first terminal sends the service access request to a tunnel layer of the first terminal;
and the tunnel layer of the first terminal sends the service access request to the tunnel layer of the second terminal from the UDP service request port.
In some embodiments, according to the method of any one of the above embodiments of the present invention, a protocol used by the UDP service request port is the same as a protocol used by a service providing port in the second terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, a port number of the UDP service request port and a port number of the service providing port in the second terminal are the same or different.
In some embodiments, according to the method in any one of the above embodiments of the present invention, after the tunnel layer of the first terminal determines the UDP service request port, before the first terminal receives a service access response sent by the second terminal through the tunnel, the method further includes:
and the tunnel layer of the first terminal sends the port number of the UDP service request port to the tunnel layer of the second terminal.
In some embodiments, the method according to any of the above embodiments of the present invention, performing the relevant operation according to the service access response, includes:
receiving data carrying a connection identifier sent by the second terminal according to the service access response;
and sending feedback to the second terminal through the connection corresponding to the connection identifier.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the sending, by the first terminal, a service access request to the second terminal through the tunnel includes:
the first terminal sends a service access request to the second terminal through the tunnel by adopting a communication mode corresponding to a connection mode of the first terminal and the second terminal;
the step of receiving, by the first terminal, a service access response sent by the second terminal through the tunnel includes:
and the first terminal receives the service access response sent by the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
According to a second aspect of the present invention, there is provided a method of accessing a service, comprising:
the second terminal establishes a tunnel capable of communicating with the first terminal;
the second terminal receives a service access request sent by the first terminal through the tunnel, wherein the service access request adopts a Transmission Control Protocol (TCP) and/or a User Datagram Protocol (UDP);
and the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, wherein the service access response adopts the TCP and/or UDP protocol.
In an embodiment, according to the method in the above embodiment of the present invention, after the second terminal receives the service access request sent by the first terminal through the tunnel, the method further includes:
a tunnel layer of the second terminal receives the service access request through the tunnel;
the tunnel layer of the second terminal and the service layer of the second terminal establish TCP connection;
and the tunnel layer of the second terminal sends the service access request to a service providing port of the service layer of the second terminal through the TCP connection.
In some embodiments, according to the method of any one of the above embodiments of the present invention, a protocol used by the service providing port is the same as a protocol used by a TCP service request port in the first terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the port number of the service providing port is the same as or different from the port number of the TCP service request port in the first terminal.
In some embodiments, before the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method according to any of the above embodiments of the present invention further includes:
and the tunnel layer of the second terminal receives the TCP connection identifier and/or the port number of the TCP service request port sent by the first terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the receiving, by the second terminal, the service access request sent by the first terminal through the tunnel includes:
a tunnel layer of the second terminal receives the service access request through the tunnel;
and the tunnel layer of the second terminal sends the service access request to a service providing port of the service layer of the second terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, a protocol used by the service providing port is the same as a protocol used by a UDP service request port in the first terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the port number of the service providing port is the same as or different from the port number of the UDP service request port in the first terminal.
In some embodiments, before the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method according to any of the above embodiments of the present invention further includes:
and the tunnel layer of the second terminal receives the port number of the UDP service request port sent by the first terminal.
In some embodiments, according to the method of any one of the above embodiments of the present invention, after the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method further includes:
sending data carrying a connection identifier to a first terminal;
and receiving feedback sent by the first terminal through the connection corresponding to the connection identifier.
In some embodiments, according to the method of any one of the above embodiments of the present invention, the receiving, by the second terminal, the service access request sent by the first terminal through the tunnel includes:
the second terminal receives the service access request sent by the first terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal;
the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, and the service access response comprises the following steps:
and the second terminal sends a service access response to the first terminal through the tunnel according to the service access request by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
According to a third aspect of the present invention, there is provided a first terminal comprising:
the establishing unit is used for establishing a tunnel which can be used for the first terminal to communicate with the second terminal;
a sending unit, configured to send a service access request to the second terminal through the tunnel, where the service access request employs a transmission control protocol TCP and/or a user datagram UDP protocol;
a receiving unit, configured to receive a service access response sent by the second terminal through the tunnel;
and the processing unit is used for executing relevant operation according to the service access response, and the service access response adopts the TCP and/or UDP protocol.
In an embodiment, according to the apparatus in the foregoing embodiment of the present invention, the establishing unit is further configured to control an application layer of the first terminal to establish a TCP connection with a tunnel layer of the first terminal;
the processing unit is further configured to control a tunnel layer of the first terminal to determine a TCP service request port;
the sending unit is further configured to control an application layer of the first terminal to send the service access request to a tunnel layer of the first terminal through the TCP connection;
the sending unit is further configured to control the tunnel layer of the first terminal to send the service access request from the TCP service request port to the tunnel layer of the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a protocol used by the TCP service request port is the same as a protocol used by the service providing port in the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a port number of the TCP service request port and a port number of the service providing port in the second terminal are the same or different.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, the sending unit is further configured to control the tunnel layer of the first terminal to send the identifier of the TCP connection and/or the port number of the TCP service request port to the tunnel layer of the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, the processing unit is further configured to control a tunnel layer of the first terminal to determine a UDP service request port;
the sending unit is further configured to control an application layer of the first terminal to send the service access request to a tunnel layer of the first terminal;
the sending unit is further configured to control the tunnel layer of the first terminal to send the service access request from the UDP service request port to the tunnel layer of the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a protocol used by the UDP service request port is the same as a protocol used by a service providing port in the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a port number of the UDP service request port and a port number of a service providing port in the second terminal are the same or different.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, the sending unit is further configured to control the tunnel layer of the first terminal to send the port number of the UDP service request port to the tunnel layer of the second terminal.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, the receiving unit is further configured to receive, according to the service access response, data carrying a connection identifier sent by the second terminal; the sending unit is further configured to send feedback to the second terminal through the connection corresponding to the connection identifier.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, when the sending unit sends the service access request to the second terminal through the tunnel, specifically:
sending a service access request to the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal;
when the receiving unit receives the service access response sent by the second terminal through the tunnel, the receiving unit specifically includes:
and receiving a service access response sent by the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
According to a third aspect of the present invention, there is provided a second terminal comprising:
the establishing unit is used for establishing a tunnel which can be used for the second terminal to communicate with the first terminal;
a receiving unit, configured to receive, through the tunnel, a service access request sent by the first terminal, where the service access request employs a transmission control protocol TCP and/or a user datagram UDP protocol;
and the sending unit is used for sending a service access response to the first terminal through the tunnel according to the service access request, wherein the service access response adopts the TCP and/or UDP protocol.
In an embodiment, according to the apparatus of the foregoing embodiment of the present invention, the receiving unit is further configured to control a tunnel layer of the second terminal to receive the service access request through the tunnel;
the establishing unit is further configured to control a tunnel layer of the second terminal and a service layer of the second terminal to establish a TCP connection;
the sending unit is further configured to control the tunnel layer of the second terminal to send the service access request to the service providing port of the service layer of the second terminal through the TCP connection.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a protocol used by the service providing port is the same as a protocol used by a TCP service request port in the first terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a port number of the service providing port is the same as or different from a port number of a TCP service request port in the first terminal.
In some embodiments, according to the apparatus of any preceding embodiment of the present invention, the receiving unit is further configured to control a tunnel layer of the second terminal to receive an identifier of the TCP connection and/or a port number of the TCP service request port sent by the first terminal.
In some embodiments, according to the apparatus of any of the foregoing embodiments of the present invention, the receiving unit is further configured to control a tunnel layer of the second terminal to receive the service access request through the tunnel;
the sending unit is further configured to control the tunnel layer of the second terminal to send the service access request to a service providing port of the service layer of the second terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a protocol used by the service providing port is the same as a protocol used by a UDP service request port in the first terminal.
In some embodiments, according to the apparatus of any one of the above embodiments of the present invention, a port number of the service providing port is the same as or different from a port number of the UDP service request port in the first terminal.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, the receiving unit is further configured to control a tunnel layer of the second terminal to receive a port number of the UDP service request port sent by the first terminal.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, the sending unit is further configured to send data carrying a connection identifier to the first terminal;
the receiving unit is further configured to receive feedback sent by the first terminal through a connection corresponding to the connection identifier.
In some embodiments, according to the apparatus of any one of the foregoing embodiments of the present invention, when the receiving unit receives the service access request sent by the first terminal through the tunnel, specifically:
the receiving unit receives a service access request sent by the first terminal through the tunnel by adopting a communication mode corresponding to a connection mode of the first terminal and the second terminal;
when the sending unit sends a service access response to the first terminal through the tunnel according to the service access request, the sending unit specifically includes:
and the sending unit sends a service access response to the first terminal through the tunnel according to the service access request by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
In an embodiment of the present invention, a method for accessing a service is provided: the method comprises the steps that a first terminal establishes a tunnel capable of communicating with a second terminal; the first terminal sends a service access request to the second terminal through the tunnel, wherein the service access request adopts a TCP (Transmission Control Protocol) and/or a UDP (user data Protocol) Protocol; the first terminal receives a service access response sent by the second terminal through the tunnel, and executes related operations according to the service access response, wherein the service access response adopts the TCP and/or UDP protocol; in the scheme, a first terminal establishes a tunnel capable of communicating with a second terminal; the communication is carried out through the tunnel, the service access request and the service access response transmitted through the tunnel adopt TCP and/or UDP protocols, the TCP and UDP protocols are common in the communication field, an open source library, a framework and a program based on the protocols are very common, and a new protocol is not required to be defined, so that the defect of low service access efficiency in the prior art can be overcome.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Fig. 1 schematically shows a flow diagram of a method 10 of accessing a service according to an embodiment of the invention. As shown in fig. 1, the method may include steps 100, 110, and 120.
Step 100: the method comprises the steps that a first terminal establishes a tunnel capable of communicating with a second terminal;
step 110: the first terminal sends a service access request to the second terminal through the tunnel, wherein the service access request adopts a TCP and/or UDP protocol;
step 120: and the first terminal receives a service access response sent by the second terminal through the tunnel, and executes related operation according to the service access response, wherein the service access response adopts the TCP and/or UDP protocol.
In the embodiment of the invention, the second terminal interacts with the first terminal in an auxiliary mode. The interaction of the second terminal with the first terminal in an assisted manner can be understood as follows: the first terminal is an independent device, has one or more functions, and can be used independently, and the second terminal has an effect of providing an additional function or an auxiliary function for the first terminal, and the function is more single, and generally needs to be connected with the first terminal to be used.
In the embodiment of the present invention, data transmitted by a first terminal and a second terminal through a tunnel is encapsulated in a certain specification, for example, a packet specification in the tunnel is defined, bytes 0 to 3 represent the entire packet length, bytes 4 to 5 represent operation and status identifiers (one bit corresponds to each protocol operation and status, for example, 0x01 represents a request to establish a TCP connection, 0x02 represents to close the TCP connection, 0x04 represents data transmission, 0x08 represents a connection error, etc.), bytes 6 to 9 represent a TCP connection identifier used for distinguishing from other TCP connection data, bytes 10 to 17 represent an ending data offset counted from the reception of the first byte data, that is, a reception sliding window, which can be currently received by a current tunnel layer, and byte 18 represents data sent by a requesting application.
In this embodiment of the present invention, when the first terminal sends the service access request to the second terminal through the tunnel, optionally, the following manner may be adopted:
the application layer of the first terminal and the tunnel layer of the first terminal establish TCP connection;
a tunnel layer of the first terminal determines a TCP service request port;
the application layer of the first terminal sends the service access request to the tunnel layer of the first terminal through the TCP connection;
and the tunnel layer of the first terminal sends the service access request to the tunnel layer of the second terminal from the TCP service request port.
In this embodiment of the present invention, optionally, a protocol used by the TCP service request port is the same as a protocol used by the service providing port in the second terminal.
For example, if the service providing port uses the TCP protocol, the protocol used by the TCP service requesting port is the TCP protocol.
In the embodiment of the present invention, optionally, the port number of the TCP service request port is the same as or different from the port number of the service providing port in the second terminal.
In this embodiment of the present invention, further, after the application layer of the first terminal establishes a TCP connection with the tunnel layer of the first terminal, and before the first terminal receives a service access response sent by the second terminal through the tunnel, the method further includes the following operations:
and the tunnel layer of the first terminal sends the TCP connection identifier and/or the port number of the TCP service request port to the tunnel layer of the second terminal.
In this embodiment of the present invention, when the first terminal sends the service access request to the second terminal through the tunnel, optionally, the following manner may be adopted:
a tunnel layer of the first terminal determines a UDP service request port;
the application layer of the first terminal sends the service access request to a tunnel layer of the first terminal;
and the tunnel layer of the first terminal sends the service access request to the tunnel layer of the second terminal from the UDP service request port.
In this embodiment of the present invention, optionally, a protocol used by the UDP service request port is the same as a protocol used by a service providing port in the second terminal.
In this embodiment of the present invention, optionally, a port number of the UDP service request port is the same as or different from a port number of a service providing port in the second terminal.
In this embodiment of the present invention, further, after the tunnel layer of the first terminal determines the UDP service request port, before the first terminal receives a service access response sent by the second terminal through the tunnel, the method further includes the following operations:
and the tunnel layer of the first terminal sends the port number of the UDP service request port to the tunnel layer of the second terminal.
In the embodiment of the present invention, when the relevant operation is executed according to the service access response, optionally, the following manner may be adopted:
receiving data carrying a connection identifier sent by the second terminal according to the service access response;
and sending feedback to the second terminal through the connection corresponding to the connection identifier.
In this embodiment of the present invention, when the first terminal sends the service access request to the second terminal through the tunnel, optionally, the following manner may be adopted:
the first terminal sends a service access request to the second terminal through the tunnel by adopting a communication mode corresponding to a connection mode of the first terminal and the second terminal;
the step of receiving, by the first terminal, a service access response sent by the second terminal through the tunnel includes:
and the first terminal receives the service access response sent by the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
For example, if the first terminal and the second terminal are connected by USB, the first terminal sends a service access request to the second terminal through a tunnel in a USB communication manner, or receives a service access response sent by the second terminal.
In the embodiment of the invention, the service access response can be operations such as returning data, closing connection, refusing connection and the like.
In the scheme, the first terminal and the second terminal communicate through the tunnel, the service access request and the service access response transmitted through the tunnel both adopt TCP and/or UDP protocols, the TCP and UDP protocols are common in the communication field, and an open source library, a framework and a program based on the protocols are very common without defining a new protocol, so that the defect of low access service efficiency in the prior art can be overcome.
In the embodiment of the invention, the service layer is separated from the physical communication layer between the two terminals, so that a new protocol does not need to be redefined when the communication mode between the first terminal and the second terminal is changed, for example, when the communication mode between the first terminal and the second terminal is converted from a USB mode to a Bluetooth mode, the new protocol does not need to be redefined.
Fig. 2 schematically shows a flow diagram of a method 20 of accessing a service according to an embodiment of the invention. As shown in fig. 2, the method may include steps 200, 210, and 220.
Step 200: the second terminal establishes a tunnel capable of communicating with the first terminal;
step 210: the second terminal receives a service access request sent by the first terminal through the tunnel, wherein the service access request adopts a Transmission Control Protocol (TCP) and/or a User Datagram Protocol (UDP);
step 220: and the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, wherein the service access response adopts the TCP and/or UDP protocol.
In the embodiment of the invention, the second terminal interacts with the first terminal in an auxiliary mode. The interaction of the second terminal with the first terminal in an assisted manner can be understood as follows: the first terminal is an independent device, has one or more functions, and can be used independently, and the second terminal has an effect of providing an additional function or an auxiliary function for the first terminal, and the function is more single, and generally needs to be connected with the first terminal to be used.
In the embodiment of the present invention, data transmitted by a first terminal and a second terminal through a tunnel is encapsulated according to a certain specification, for example, a specification of a data packet in the tunnel is defined, bytes 0 to 3 represent the length of the whole data packet, bytes 4 to 5 represent operation and status identifiers (one bit corresponds to each protocol operation and status, for example, 0x01 represents a request to establish a TCP connection, 0x02 represents a closing of the TCP connection, 0x04 represents data transmission, 0x08 represents a connection error, etc.), bytes 6 to 9 represent a TCP connection identifier for distinguishing from other TCP connection data, bytes 10 to 17 represent an offset of a cutoff data count since the first byte data is received at the current tunnel end, that is, a reception sliding window, and byte 18 represents data sent by a requesting application.
In this embodiment of the present invention, after the second terminal receives the service access request sent by the first terminal through the tunnel, the method further includes the following operations:
a tunnel layer of the second terminal receives the service access request through the tunnel;
the tunnel layer of the second terminal and the service layer of the second terminal establish TCP connection;
and the tunnel layer of the second terminal sends the service access request to a service providing port of the service layer of the second terminal through the TCP connection.
In this embodiment of the present invention, optionally, a protocol used by the service providing port is the same as a protocol used by a TCP service request port in the first terminal.
For example, if the service providing port uses the TCP protocol, the protocol used by the TCP service requesting port is the TCP protocol.
In this embodiment of the present invention, optionally, the port number of the service providing port is the same as or different from the port number of the TCP service request port in the first terminal.
In this embodiment of the present invention, further, before the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method further includes the following operations:
and the tunnel layer of the second terminal receives the TCP connection identifier and/or the port number of the TCP service request port sent by the first terminal.
In this embodiment of the present invention, when the second terminal receives the service access request sent by the first terminal through the tunnel, optionally, the following manner may be adopted:
a tunnel layer of the second terminal receives the service access request through the tunnel;
and the tunnel layer of the second terminal sends the service access request to a service providing port of the service layer of the second terminal.
In this embodiment of the present invention, optionally, a protocol used by the service providing port is the same as a protocol used by a UDP service request port in the first terminal.
In this embodiment of the present invention, optionally, the port number of the service providing port is the same as or different from the port number of the UDP service request port in the first terminal.
In this embodiment of the present invention, further, before the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method further includes the following operations:
and the tunnel layer of the second terminal receives the port number of the UDP service request port sent by the first terminal.
In this embodiment of the present invention, after the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, the method further includes the following operations:
sending data carrying a connection identifier to a first terminal;
and receiving feedback sent by the first terminal through the connection corresponding to the connection identifier.
In this embodiment of the present invention, when the second terminal receives the service access request sent by the first terminal through the tunnel, optionally, the following manner may be adopted:
the second terminal receives the service access request sent by the first terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal;
the second terminal sends a service access response to the first terminal through the tunnel according to the service access request, and the service access response comprises the following steps:
and the second terminal sends a service access response to the first terminal through the tunnel according to the service access request by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
For example, if the first terminal and the second terminal are connected by USB, the first terminal sends a service access request to the second terminal through a tunnel in a USB communication manner, or receives a service access response sent by the second terminal.
In the embodiment of the invention, the service access response can be operations such as returning data, closing connection, refusing connection and the like.
In the scheme, the first terminal and the second terminal communicate through the tunnel, the service access request and the service access response transmitted through the tunnel adopt TCP and/or UDP protocols, the TCP/UDP protocols are common in the communication field, and an open source library, a framework and a program based on the protocols are very common without defining a new protocol, so that the defect of low access service efficiency in the prior art can be overcome.
In the embodiment of the invention, the service layer is separated from the physical communication layer between the two terminals, so that a new protocol does not need to be redefined when the communication mode between the first terminal and the second terminal is changed, for example, when the communication mode between the first terminal and the second terminal is converted from a USB mode to a Bluetooth mode, the new protocol does not need to be redefined.
An embodiment of the present invention further provides an embodiment of accessing a service, which is shown in fig. 3.
Step 300: the first terminal establishes a tunnel capable of communicating with the second terminal.
The second terminal waits for connection or data at the service providing port to provide service, and the first terminal selects an idle TCP service request port which adopts the same protocol as the protocol adopted by the service providing port to listen to or wait for the data.
Step 310: and the tunnel layer of the first terminal sends a service access request to the second terminal through the tunnel, wherein the service access request adopts a TCP and/or UDP protocol.
In this step, data transmitted by the first terminal and the second terminal through the tunnel is encapsulated in a certain specification, such as defining a specification of a data packet in the tunnel, bytes 0 to 3 indicate a length of the whole data packet, bytes 4 to 5 are operation and status identifiers (one bit corresponds to each protocol operation and status, such as 0x01 indicating that a TCP connection is requested to be established, 0x02 indicating that the TCP connection is closed, 0x04 indicating data transmission, 0x08 indicating a connection error, etc.), bytes 6 to 9 indicate a TCP connection identifier for distinguishing from other TCP connection data, bytes 10 to 17 indicate an offset of an ending data counted from the data of the first byte received currently receivable by the current tunnel layer, i.e. a reception sliding window, and byte 18 indicates data sent by the requesting application.
Step 320: and after receiving the service access request, the tunnel layer of the second terminal decapsulates according to the agreed encapsulation specification, and initiates operations to the service layer port, such as establishing a TCP connection, transmitting TCP data, and the like.
Step 330: the second terminal sends a service access response to the first terminal through the tunnel.
The service access response may be packets such as return data, close connection, and reject connection.
And the first terminal and the second terminal continuously carry out interactive communication according to the steps.
It should be noted that the above steps are only a specific case of accessing a service, and according to actual needs, the first terminal may provide multiple service providing ports on one service, or the second terminal has multiple service providing ports to provide services, and the first terminal only needs to open as many TCP service requesting ports according to the above steps to establish one-to-one mapping of ports.
Referring to fig. 4, in the embodiment of the present invention, a first terminal 40 is further provided, which includes:
an establishing unit 400, configured to establish a tunnel through which the first terminal can communicate with a second terminal;
a sending unit 410, configured to send a service access request to the second terminal through the tunnel, where the service access request employs a transmission control protocol TCP and/or a user datagram UDP protocol;
a receiving unit 420, configured to receive a service access response sent by the second terminal through the tunnel;
a processing unit 430, configured to perform relevant operations according to the service access response, where the service access response employs the TCP and/or UDP protocol.
In the embodiment of the invention, the second terminal interacts with the first terminal in an auxiliary mode. The interaction of the second terminal with the first terminal in an assisted manner can be understood as follows: the first terminal is an independent device, has one or more functions, and can be used independently, and the second terminal has an effect of providing an additional function or an auxiliary function for the first terminal, and the function is more single, and generally needs to be connected with the first terminal to be used.
In the embodiment of the present invention, data transmitted by a first terminal and a second terminal through a tunnel is encapsulated according to a certain specification, for example, a packet specification in the tunnel is defined, bytes 0 to 3 represent the length of the entire packet, bytes 4 to 5 represent operation and status identifiers (one bit corresponds to each protocol operation and status, for example, 0x01 represents a request to establish a TCP connection, 0x02 represents a closing TCP connection, 0x04 represents data transmission, 0x08 represents a connection error, etc.), bytes 6 to 9 represent a TCP connection identifier for distinguishing from other TCP connection data, bytes 10 to 17 represent an ending data offset counted from the receipt of the first byte data, that is, a reception sliding window, which can be currently received by a current tunnel layer, and byte 18 represents data sent by a requesting application.
In this embodiment of the present invention, further, the establishing unit 400 is further configured to control an application layer of the first terminal and a tunnel layer of the first terminal to establish a TCP connection;
the processing unit 430 is further configured to control a tunnel layer of the first terminal to determine a TCP service request port;
the sending unit 410 is further configured to control an application layer of the first terminal to send the service access request to a tunnel layer of the first terminal through the TCP connection;
the sending unit 410 is further configured to control the tunnel layer of the first terminal to send the service access request from the TCP service request port to the tunnel layer of the second terminal.
In this embodiment of the present invention, optionally, a protocol used by the TCP service request port is the same as a protocol used by the service providing port in the second terminal.
For example, if the service providing port uses the TCP protocol, the protocol used by the TCP service requesting port is the TCP protocol.
In the embodiment of the present invention, optionally, the port number of the TCP service request port is the same as or different from the port number of the service providing port in the second terminal.
In this embodiment of the present invention, the sending unit 410 is further configured to control the tunnel layer of the first terminal to send the identifier of the TCP connection and/or the port number of the TCP service request port to the tunnel layer of the second terminal.
In this embodiment of the present invention, further, the processing unit 430 is further configured to control a tunnel layer of the first terminal to determine a UDP service request port;
the sending unit 410 is further configured to control an application layer of the first terminal to send the service access request to a tunnel layer of the first terminal;
the sending unit 410 is further configured to control the tunnel layer of the first terminal to send the service access request from the UDP service request port to the tunnel layer of the second terminal.
In this embodiment of the present invention, optionally, a protocol used by the UDP service request port is the same as a protocol used by a service providing port in the second terminal.
In this embodiment of the present invention, optionally, a port number of the UDP service request port is the same as or different from a port number of a service providing port in the second terminal.
In this embodiment of the present invention, the sending unit 410 is further configured to control the tunnel layer of the first terminal to send the port number of the UDP service request port to the tunnel layer of the second terminal.
In this embodiment of the present invention, the receiving unit 420 is further configured to receive, according to the service access response, data carrying a connection identifier sent by the second terminal; the sending unit 410 is further configured to send feedback to the second terminal through the connection corresponding to the connection identifier.
In this embodiment of the present invention, optionally, when the sending unit 410 sends the service access request to the second terminal through the tunnel, specifically, the sending unit is to:
sending a service access request to the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal;
when the receiving unit 420 receives the service access response sent by the second terminal through the tunnel, the specific steps are:
and receiving a service access response sent by the second terminal through the tunnel by adopting a communication mode corresponding to the connection mode of the first terminal and the second terminal.
For example, if the first terminal and the second terminal are connected by USB, the first terminal sends a service access request to the second terminal through a tunnel in a USB communication manner, or receives a service access response sent by the second terminal.
In the embodiment of the invention, the service access response can be operations such as returning data, closing connection, refusing connection and the like.
In the scheme, the first terminal and the second terminal communicate through the tunnel, the service access request and the service access response transmitted through the tunnel adopt TCP and/or UDP protocols, the TCP/UDP protocols are common in the communication field, and an open source library, a framework and a program based on the protocols are very common without defining a new protocol, so that the defect of low access service efficiency in the prior art can be overcome.
In the embodiment of the invention, the service layer is separated from the physical communication layer between the two terminals, so that a new protocol does not need to be redefined when the communication mode between the first terminal and the second terminal is changed, for example, when the communication mode between the first terminal and the second terminal is converted from a USB mode to a Bluetooth mode, the new protocol does not need to be redefined.
Referring to fig. 5, in the embodiment of the present invention, a second terminal 50 is further provided, which includes:
an establishing unit 500, configured to establish a tunnel through which the second terminal can communicate with the first terminal;
a receiving unit 510, configured to receive, through the tunnel, a service access request sent by the first terminal, where the service access request employs a transmission control protocol TCP and/or a user datagram UDP protocol;
a sending unit 520, configured to send a service access response to the first terminal through the tunnel according to the service access request, where the service access response employs the TCP and/or UDP protocol.
In the embodiment of the invention, the second terminal interacts with the first terminal in an auxiliary mode. The interaction of the second terminal with the first terminal in an assisted manner can be understood as follows: the first terminal is an independent device, has one or more functions, and can be used independently, and the second terminal has an effect of providing an additional function or an auxiliary function for the first terminal, and the function is more single, and generally needs to be connected with the first terminal to be used.
In the embodiment of the present invention, data transmitted by a first terminal and a second terminal through a tunnel is encapsulated according to a certain specification, for example, a packet specification in the tunnel is defined, bytes 0 to 3 represent the length of the entire packet, bytes 4 to 5 represent operation and status identifiers (one bit corresponds to each protocol operation and status, for example, 0x01 represents a request to establish a TCP connection, 0x02 represents a closing TCP connection, 0x04 represents data transmission, 0x08 represents a connection error, etc.), bytes 6 to 9 represent a TCP connection identifier for distinguishing from other TCP connection data, bytes 10 to 17 represent an ending data offset counted from the receipt of the first byte data, that is, a reception sliding window, which can be currently received by a current tunnel layer, and byte 18 represents data sent by a requesting application.
In this embodiment of the present invention, the receiving unit 510 is further configured to control a tunnel layer of the second terminal to receive the service access request through the tunnel;
the establishing unit 500 is further configured to control a tunnel layer of the second terminal to establish a TCP connection with a service layer of the second terminal;
the sending unit 520 is further configured to control the tunnel layer of the second terminal to send the service access request to the service providing port of the service layer of the second terminal through the TCP connection.
In this embodiment of the present invention, optionally, a protocol used by the service providing port is the same as a protocol used by a TCP service request port in the first terminal.
For example, if the service providing port uses the TCP protocol, the protocol used by the TCP service requesting port is the TCP protocol.
In this embodiment of the present invention, optionally, the port number of the service providing port is the same as or different from the port number of the TCP service request port in the first terminal.
In this embodiment of the present invention, the receiving unit 510 is further configured to control a tunnel layer of the second terminal to receive the identifier of the TCP connection and/or the port number of the TCP service request port sent by the first terminal.
In this embodiment of the present invention, the receiving unit 510 is further configured to control a tunnel layer of the second terminal to receive the service access request through the tunnel;
the sending unit 520 is further configured to control the tunnel layer of the second terminal to send the service access request to a service providing port of the service layer of the second terminal.
In this embodiment of the present invention, optionally, a protocol used by the service providing port is the same as a protocol used by a UDP service request port in the first terminal.
In this embodiment of the present invention, optionally, the port number of the service providing port is the same as or different from the port number of the UDP service request port in the first terminal.
In this embodiment of the present invention, the receiving unit 510 is further configured to control a tunnel layer of the second terminal to receive a port number of the UDP service request port sent by the first terminal.
In this embodiment of the present invention, the element 520 is further configured to send data carrying the connection identifier to the first terminal;
the receiving unit 510 is further configured to receive feedback sent by the first terminal through a connection corresponding to the connection identifier.
In this embodiment of the present invention, optionally, when the receiving unit 510 receives the service access request sent by the first terminal through the tunnel, specifically, the receiving unit is to:
the receiving unit 510 receives a service access request sent by the first terminal through the tunnel by using a communication mode corresponding to a connection mode of the first terminal and the second terminal;
when the sending unit 520 sends the service access response to the first terminal through the tunnel according to the service access request, specifically:
the sending unit 520 sends a service access response to the first terminal through the tunnel according to the service access request by using a communication mode corresponding to a connection mode of the first terminal and the second terminal.
For example, if the first terminal and the second terminal are connected by USB, the first terminal sends a service access request to the second terminal through a tunnel in a USB communication manner, or receives a service access response sent by the second terminal.
In the embodiment of the invention, the service access response can be operations such as returning data, closing connection, refusing connection and the like.
In the scheme, the first terminal and the second terminal communicate through the tunnel, the service access request and the service access response transmitted through the tunnel adopt TCP and/or UDP protocols, the TCP/UDP protocols are common in the communication field, and an open source library, a framework and a program based on the protocols are very common without defining a new protocol, so that the defect of low access service efficiency in the prior art can be overcome.
In the embodiment of the invention, the service layer is separated from the physical communication layer between the two terminals, so that a new protocol does not need to be redefined when the communication mode between the first terminal and the second terminal is changed, for example, when the communication mode between the first terminal and the second terminal is converted from a USB mode to a Bluetooth mode, the new protocol does not need to be redefined.
The methods and apparatus provided herein are not inherently related to any particular computer, virtual machine system, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a device will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the apparatus of an embodiment may be adaptively changed and disposed in one or more apparatuses other than the embodiment. Several modules of embodiments may be combined into one module or unit or assembly and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-assemblies. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or modules are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the claims, any of the claimed embodiments may be used in any combination.
Various apparatus embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the modules in an apparatus according to embodiments of the present invention. The present invention may also be embodied as apparatus programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.