A kind of data communications method, device, equipment and mediumTechnical field
The present invention relates to data communication fields, more particularly to a kind of data communications method, device, equipment and medium.
Background technique
With the development of network technology, cloud computing is increasingly becoming the mainstream applications mode currently for network technology, thereforeInternet enterprises release corresponding cloud service platform one after another.Cloud service be related service Internet-based increase, using andDelivery mode, usually provides a user the resource of virtualization by internet, and user can be connect by modes such as computer, mobile phonesThe computing resource or storage resource for entering data center, and then being provided according to demand using cloud service carry out relevant data operation orData storage.
The normal operation of cloud service is needed by the hardware device of bottom as resource support, and by the hardware device group of blankAt cloud service underlying device cluster when, then need to be disposed accordingly using the hardware device of blank as to deployment facility.Current enterprise generally requires to be treated that deployment facility carries out discovery and batch is disposed by user equipment, due to waiting for when batch is disposedDeployment facility is not yet assigned IP address, therefore user equipment and to first pass through LLDP (link layer discovery) between deployment facility in advanceAgreement establishes Socket connection based on MAC Address between network interface card, to deployment facility and user equipment persistently to itself netThe Socket connection of card is monitored, and when having listened to data arrival, is received and is responded to data, realizes user with thisEquipment and to the interaction between deployment facility, and then realize that user equipment treats the deployment of deployment facility.But as user setsThe standby and network interface card quantity to deployment facility gradually increases, and still uses current communication means, will lead to the money in hardware deviceSource occupancy is relatively large, easily reduces hardware device to the response efficiency of incoming data, or even influence hardware device the operation is stableProperty.
It can be seen that a kind of data communications method is provided, and with opposite reduction to the resource occupation of hardware device, so it is oppositeHardware device is improved to the response efficiency of incoming data, and guarantees the job stability of hardware device, is those skilled in the artProblem to be solved.
Summary of the invention
The object of the present invention is to provide a kind of data communications method, device, equipment and media, are set with opposite reduction to hardwareStandby resource occupation, and then hardware device is improved to the response efficiency of incoming data relatively, and guarantees that the work of hardware device is steadyIt is qualitative.
In order to solve the above technical problems, the present invention provides a kind of data communications method, comprising:
Network interface card is traversed, and records the target network interface card established and have Socket connection;
The Socket connection of target network interface card is monitored according to prefixed time interval;
When listen to target Socket connection be passed to data packet when, received data packet is simultaneously handled.
Preferably, the Socket connection of target network interface card is monitored according to prefixed time interval specifically:
The Socket connection of target network interface card is monitored in such a way that single thread loops through according to prefixed time interval.
Preferably, record establishes the target network fixture body for having Socket connection are as follows:
Record establishes the MAC Address for having the target network interface card of Socket connection;
Correspondingly, according to prefixed time interval by single thread loop through in a manner of to the Socket of target network interface card connect intoRow is monitored specifically:
Connected in such a way that single thread loops through according to Socket of the MAC Address to target network interface card according to prefixed time intervalTap into capable monitoring.
Preferably, this method further comprises:
When the process of received data packet is deposited when abnormal, generation includes the exception of the relevant information of target Socket connectionPrompt, and abnormal prompt is presented to user.
Preferably, network interface card is traversed, and records the target network fixture body established and have Socket connection are as follows:
Traversal is in the network interface card of initiate mode, and records the target network interface card established and have Socket connection.
In addition, the present invention also provides a kind of data communication equipments, comprising:
Spider module for traversing network interface card, and records the target network interface card established and have Socket connection;
Module is monitored at interval, for monitoring according to prefixed time interval the Socket connection of target network interface card;
Receiving processing module, for when listen to target Socket connection be passed to data packet when, received data packet simultaneously carries outProcessing.
In addition, the present invention also provides a kind of data communications equipment, comprising:
Memory, for storing computer program;
Processor is realized when for executing computer program such as the step of above-mentioned data communications method.
In addition, being stored with meter on computer readable storage medium the present invention also provides a kind of computer readable storage mediumCalculation machine program is realized when computer program is executed by processor such as the step of above-mentioned data communications method.
Data communications method provided by the present invention is traversed the network interface card of itself first, is obtained with this and established SocketThe target network interface card of connection, and then the Socket connection of target network interface card is monitored according to prefixed time interval, this is learned with thisThe whether incoming data packet of Socket connection, when listen to there are target Socket connection it is incoming have data packet when, then by the meshIt marks Socket connection and receives its incoming data packet, and the data packet received is handled.Since this method is according to defaultTime interval monitors the Socket connection of target network interface card, i.e., discontinuous to the monitoring of Socket connection, and each monitoringBetween be spaced certain duration, therefore monitor Socket connection continuously compared to Current hardware equipment to obtain the communication of data packetFor mode, this method avoids the lasting resource for occupying hardware device to a certain extent, reduces on the whole to hardwareThe resource occupation of equipment, and then opposite ensure that hardware device to the response efficiency of incoming data, and ensure that hardware deviceJob stability.In addition, the present invention also provides a kind of data communication equipment, equipment and medium, beneficial effect is same as above.
Detailed description of the invention
In order to illustrate the embodiments of the present invention more clearly, attached drawing needed in the embodiment will be done simply belowIt introduces, it should be apparent that, drawings in the following description are only some embodiments of the invention, for ordinary skill peopleFor member, without creative efforts, it is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of flow chart of data communications method provided in an embodiment of the present invention;
Fig. 2 is a kind of structure chart of data communication equipment provided in an embodiment of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, completeSite preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, rather than whole embodiments.Based on thisEmbodiment in invention, those of ordinary skill in the art are without making creative work, obtained every otherEmbodiment belongs to the scope of the present invention.
Core of the invention is to provide a kind of data communications method, with opposite reduction to the resource occupation of hardware device, intoAnd hardware device is improved to the response efficiency of incoming data relatively, and guarantee the job stability of hardware device.
In order to enable those skilled in the art to better understand the solution of the present invention, with reference to the accompanying drawings and detailed descriptionThe present invention is described in further detail.
Embodiment one
Fig. 1 is a kind of flow chart of data communications method provided in an embodiment of the present invention.Referring to FIG. 1, data communication sideThe specific steps of method include:
Step S10: traversal network interface card, and record the target network interface card established and have Socket connection.
It should be noted that network interface card is networking component of the work in link layer, it is that computer and transmission are connected in local area networkThe interface of medium, the physical connection and electric signal being not only able to achieve between local network transport medium match, and further relate to the hair of frameIt send and receives, the encapsulation of frame and opening, medium access control, coding and decoding and the function of data buffer storage of data etc..
The executing subject of this step should be the hardware device itself for carrying out data communication, and the net traversed in this stepCard, is installed in hardware device in advance, and hardware device is communicated by network interface card with other hardware devices.In addition, the net in this stepCard can may be wireless network card for wired network adapter, and the quantity of network interface card can not only be one, should be according to hardware deviceDepending on locating specific communication scenes, it is not specifically limited herein.
In this step, hardware device learns with this and records foundation have Socket connection by the network interface card of traversal itselfTarget network interface card.Wherein Socket connection establish network connection when uses, between hardware device when successful connection, both ends it is hardA Socket example can be generated in part equipment, and then each hardware device passes through the Socket example of operation itself, completesSession needed between hardware device, therefore when establishing in target network interface card has Socket connection, then illustrate that hardware device is just logicalIt crosses the target network interface card and other hardware devices carries out data communication.
Step S11: the Socket connection of target network interface card is monitored according to prefixed time interval.
Focusing on for this step is according to certain time between the operation that the Socket of target network interface card connection is monitoredEvery progress, that is to say, that this step is not carried out continuously the monitoring of Socket connection, and to the every of Socket connectionEqual certain interval of time again monitors the Socket connection after secondary monitoring.Purpose is can to subtract in interval time sectionFew resource occupation to hardware device, it is ensured that the work of the efficient stable of hardware device.
Step S12: when listen to target Socket connection be passed to data packet when, received data packet is simultaneously handled.
This step is to listen to that there are target Socket to be connected with when the Socket connection to target network interface card is monitoredWhen data packet is passed to, then receive the incoming data packet of target Socket connection, and carry out subsequent processing, due to differentCommunication objective between hardware device has differences under communication scenes, therefore this step does not limit the processing of data packetFixed, the emphasis of this step is only that when listening to the incoming data packet of target Socket connection, is received to its data packetAnd processing, being normally carried out for data communication between hardware device is ensured with this.
Data communications method provided by the present invention is traversed the network interface card of itself first, is obtained with this and established SocketThe target network interface card of connection, and then the Socket connection of target network interface card is monitored according to prefixed time interval, this is learned with thisThe whether incoming data packet of Socket connection, when listen to there are target Socket connection it is incoming have data packet when, then by the meshIt marks Socket connection and receives its incoming data packet, and the data packet received is handled.Since this method is according to defaultTime interval monitors the Socket connection of target network interface card, i.e., discontinuous to the monitoring of Socket connection, and each monitoringBetween be spaced certain duration, therefore monitor Socket connection continuously compared to Current hardware equipment to obtain the communication of data packetFor mode, this method avoids the lasting resource for occupying hardware device to a certain extent, reduces on the whole to hardwareThe resource occupation of equipment, and then opposite ensure that hardware device to the response efficiency of incoming data, and ensure that hardware deviceJob stability.
Embodiment two
On the basis of the above embodiments, the present invention also provides a series of preferred embodiments.
As a preferred embodiment, monitoring according to prefixed time interval the Socket connection of target network interface cardSpecifically:
The Socket connection of target network interface card is monitored in such a way that single thread loops through according to prefixed time interval.
It should be noted that present embodiment only opens a thread, and to target network interface card in a manner of searching loopThe monitoring of Socket connection progress prefixed time interval.Specifically, the thread is only in accordance with pre- when the quantity of target network interface card is 1If time interval monitors the Socket connection of the target network interface card;When the quantity of target network interface card be greater than 1 when, the thread everyPrefixed time interval monitors the Socket connection of each target network interface card one by one that is, by the way of poll, herein signified pollSuccessively the Socket connection of each target network interface card is monitored, until completing the monitoring to target complete network interface card.Due toIn view of network interface card quantity possessed by the hardware device in practical application scene is often more, and then the target network in data communicationThe quantity of card is also relatively more, monitors if opening multiple thread parallels corresponding network interface card, excessive thread can account forWith certain hardware device resources, therefore present embodiment loops through each target network interface card by way of single thread, with thisIt realizes the monitoring to the Socket connection in target network interface card, opposite can reduce thread to the occupancy of hardware device resources, into oneStep improves the working efficiency and stability of hardware device.
On the basis of the above embodiment, as a preferred embodiment, record, which is established, Socket connectionTarget network fixture body are as follows:
Record establishes the MAC Address for having the target network interface card of Socket connection;
Correspondingly, according to prefixed time interval by single thread loop through in a manner of to the Socket of target network interface card connect intoRow is monitored specifically:
Connected in such a way that single thread loops through according to Socket of the MAC Address to target network interface card according to prefixed time intervalTap into capable monitoring.
It should be noted that since MAC Address is for one network interface card of unique identification in a network, if an equipment have one orMultiple network interface cards, then each network interface card requires to possess unique MAC Address, therefore each MAC Address can be corresponded to accurately accordinglyTarget network interface card.Present embodiment is recorded MAC Address as the identity of target network interface card, and then according to MAC Address pairCorresponding target network card is monitored, and can improve the accuracy monitored Socket connection relatively, it is ensured that data communicationReliability.
In addition, as a preferred embodiment, this method further comprises:
When the process of received data packet is deposited when abnormal, generation includes the exception of the relevant information of target Socket connectionPrompt, and abnormal prompt is presented to user.
It is understood that due to consideration that when being deposited when abnormal by the process of Socket connection received data packet,Hardware device can not normally get the data packet, and then the normal communication that may be unable to ensure between hardware device, therefore this realityIt applies in mode, when the process of received data packet is deposited when abnormal, generation includes the different of the relevant information of target Socket connectionOften prompt, and to user present abnormal prompt, by user present include target Socket connection relevant information it is differentOften prompt, to ensure user while knowing abnormal occur, the specific Socket connection being abnormal being capable of phase with thisTo ensuring that user excludes abnormal whole efficiency, and then guarantee the reliability of data communication.
On the basis of a series of above-mentioned embodiments, as a preferred embodiment, traversal network interface card, and record and buildThe vertical target network fixture body for having Socket connection are as follows:
Traversal is in the network interface card of initiate mode, and records the target network interface card established and have Socket connection.
It should be noted that due to consideration that in practical applications, the network interface card in hardware device is large number of, and it is not completePortion's network interface card is in initiate mode, and inevitable not yet establish of the network interface card in non-enabled state has Socket connection, therefore this implementationMode only traverses the network interface card in initiate mode that may establish Socket connection, being capable of the opposite traversal number reduced to network interface cardAmount, and then the resource overhead that traversal network interface card integrally generates is reduced, the occupancy to hardware device resources is further reduced, is improvedThe working efficiency and stability of hardware device.
Embodiment three
Hereinbefore the embodiment of data communications method is described in detail, the present invention also provides one kind and is somebody's turn to doThe corresponding data communication equipment of method, since the embodiment of device part is corresponded to each other with the embodiment of method part, dressSet part embodiment refer to method part embodiment description, wouldn't repeat here.
Fig. 2 is a kind of structure chart of data communication equipment provided in an embodiment of the present invention.Number provided in an embodiment of the present inventionAccording to communication device, comprising:
Spider module 10 for traversing network interface card, and records the target network interface card established and have Socket connection.
Module 11 is monitored at interval, for monitoring according to prefixed time interval the Socket connection of target network interface card.
Receiving processing module 12, for when listen to target Socket connection be passed to data packet when, received data packet is gone forward side by sideRow processing.
Data communication equipment provided by the present invention is traversed the network interface card of itself first, is obtained with this and established SocketThe target network interface card of connection, and then the Socket connection of target network interface card is monitored according to prefixed time interval, this is learned with thisThe whether incoming data packet of Socket connection, when listen to there are target Socket connection it is incoming have data packet when, then by the meshIt marks Socket connection and receives its incoming data packet, and the data packet received is handled.Since the present apparatus is according to defaultTime interval monitors the Socket connection of target network interface card, i.e., discontinuous to the monitoring of Socket connection, and each monitoringBetween be spaced certain duration, therefore monitor Socket connection continuously compared to Current hardware equipment to obtain the communication of data packetFor mode, the present apparatus avoids the lasting resource for occupying hardware device to a certain extent, reduces on the whole to hardwareThe resource occupation of equipment, and then opposite ensure that hardware device to the response efficiency of incoming data, and ensure that hardware deviceJob stability.
Example IV
In addition, the present invention also provides a kind of data communications equipment, comprising:
Memory, for storing computer program;
Processor is realized when for executing computer program such as the step of above-mentioned data communications method.
Data communications equipment provided by the present invention is traversed the network interface card of itself first, is obtained with this and established SocketThe target network interface card of connection, and then the Socket connection of target network interface card is monitored according to prefixed time interval, this is learned with thisThe whether incoming data packet of Socket connection, when listen to there are target Socket connection it is incoming have data packet when, then by the meshIt marks Socket connection and receives its incoming data packet, and the data packet received is handled.Since this equipment is according to defaultTime interval monitors the Socket connection of target network interface card, i.e., discontinuous to the monitoring of Socket connection, and each monitoringBetween be spaced certain duration, therefore monitor Socket connection continuously compared to Current hardware equipment to obtain the communication of data packetFor mode, this equipment avoids the lasting resource for occupying hardware device to a certain extent, reduces on the whole to hardwareThe resource occupation of equipment, and then opposite ensure that hardware device to the response efficiency of incoming data, and ensure that hardware deviceJob stability.
In addition, being stored with meter on computer readable storage medium the present invention also provides a kind of computer readable storage mediumCalculation machine program is realized when computer program is executed by processor such as the step of above-mentioned data communications method.
Computer readable storage medium provided by the present invention is traversed the network interface card of itself first, is obtained and established with thisThe target network interface card of Socket connection, and then the Socket connection of target network interface card is monitored according to prefixed time interval, with thisLearn the whether incoming data packet of the Socket connection, when listen to be passed to there are target Socket connection have data packet when, then lead toIt crosses target Socket connection and receives its incoming data packet, and the data packet received is handled.Due to this computerReadable storage medium storing program for executing monitors the Socket connection of target network interface card according to prefixed time interval, i.e. the prison to Socket connectionIt listens discontinuous, and is spaced certain duration between monitoring for each time, therefore continuously monitor Socket compared to Current hardware equipment and connectFor connecing to obtain the communication mode of data packet, this computer readable storage medium avoids lasting occupy firmly to a certain extentThe resource of part equipment reduces the resource occupation to hardware device on the whole, and then ensures hardware device to incoming relativelyThe response efficiency of data, and ensure that the job stability of hardware device.
A kind of data communications method provided by the present invention, device, equipment and medium are described in detail above.It saysEach embodiment is described in a progressive manner in bright book, and the highlights of each of the examples are the differences with other embodimentsPlace, the same or similar parts in each embodiment may refer to each other.For device, equipment disclosed in embodiment and mediumSpeech, since it is corresponded to the methods disclosed in the examples, so being described relatively simple, related place is referring to method part illustration?.It should be pointed out that for those skilled in the art, without departing from the principle of the present invention, alsoCan be with several improvements and modifications are made to the present invention, these improvement and modification also fall into the protection scope of the claims in the present inventionIt is interior.
It should also be noted that, in the present specification, relational terms such as first and second and the like be used merely to byOne entity or operation are distinguished with another entity or operation, without necessarily requiring or implying these entities or operationBetween there are any actual relationship or orders.Moreover, the terms "include", "comprise" or its any other variant meaningCovering non-exclusive inclusion, so that the process, method, article or equipment for including a series of elements not only includes thatA little elements, but also including other elements that are not explicitly listed, or further include for this process, method, article orThe intrinsic element of equipment.In the absence of more restrictions, the element limited by sentence "including a ...", is not arrangedExcept there is also other identical elements in the process, method, article or apparatus that includes the element.