WO2009030130A1 - A method and system for transmitting data - Google Patents

A method and system for transmitting data Download PDF

Info

Publication number
WO2009030130A1
WO2009030130A1 PCT/CN2008/071577 CN2008071577W WO2009030130A1 WO 2009030130 A1 WO2009030130 A1 WO 2009030130A1 CN 2008071577 W CN2008071577 W CN 2008071577W WO 2009030130 A1 WO2009030130 A1 WO 2009030130A1
Authority
WO
WIPO (PCT)
Prior art keywords
socket
data
response packet
read
new
Prior art date
Application number
PCT/CN2008/071577
Other languages
French (fr)
Chinese (zh)
Inventor
Zhigang Ye
Original Assignee
Shenzhen Coship Electronics 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 Shenzhen Coship Electronics Co., Ltd. filed Critical Shenzhen Coship Electronics Co., Ltd.
Publication of WO2009030130A1 publication Critical patent/WO2009030130A1/en

Links

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]
    • 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

Definitions

  • the invention belongs to the field of network communication, and in particular relates to a data transmission method and system.
  • the client's connection request there are two models for the client's connection request: one is that the receiver uses the iterative server model to process the client's request in turn; the other is that the receiver uses the concurrent server model for each
  • the client requests a process to process.
  • the receiving end adopts the concurrent server model, and some sub-processes are pre-derived to process client requests; the receiving end adopts a concurrent server model, and one thread is generated for each client to process; the receiving end adopts a concurrent server model, and some threads are pre-derived for processing.
  • the receiving end generally adopts a concurrent server model, and some threads are pre-derived to process client requests. Whenever a client requests, the request is submitted to a thread pool until the request is processed.
  • the prior art does not divide or divide the execution of the intermediate state of the socket, the execution state of the protocol, and the execution state of the data, or introduces such a mechanism, and the socket does not adopt a notification mechanism or is imperfect, when a network event occurs.
  • the application layer is not notified in a timely and accurate manner.
  • the purpose of the embodiments of the present invention is to provide a data transmission method and system, which aims to solve the problem that the network data transmission in the prior art is large and the application layer cannot be accurately and timely notified when a network event occurs.
  • the embodiment of the present invention is implemented by the method for sending data, and the method includes the following steps:
  • the socket After the connection is successful and the notification slot is registered for the pre-established socket, it is judged whether the data is successfully written to the data receiving end by the socket, and when the data is successfully written, the response packet of the data receiving end is read; When the write data is unsuccessful, the socket is added to the work queue, and when the socket is queried, When writing, the socket is notified to write data to the data receiving end.
  • Another object of the embodiments of the present invention is to provide a method for receiving data, the method comprising the following steps:
  • the listening socket When the connection request of the data sender is monitored through a pre-established listening socket, the listening socket reselects a new socket;
  • Determining whether the data is successfully read by the new socket processing the data when the data is successful, and writing a response packet to the data sending end; when the reading data is unsuccessful, the new socket is Joining the work queue, and continuously detecting the status of the new socket, and notifying the new socket to read data when the new socket is readable.
  • Another object of the present invention is to provide a data sending system, where the system includes: a socket establishing module, configured to establish a socket;
  • connection request sending module configured to send a network connection request to the data receiving end
  • Notifying a slot registration module for registering a notification slot of the socket when the connection is successful
  • a socket write data judging processing module configured to determine, after the notification slot registration module registers the notification slot of the socket, whether the data is successfully written to the data receiving end by the socket, when writing data If successful, the response packet of the data receiving end is read; when the writing data is unsuccessful, the socket is added to the working queue, and when the socket is readable, the socket is notified to the The data receiving end writes data.
  • Another object of the present invention is to provide a data receiving system, where the system includes: a listening socket establishment determining module, configured to establish a listening socket, and determine whether the socket monitoring is successful;
  • connection request judging module configured to determine, after the monitoring socket is successfully monitored, whether the listening socket listens to a connection request of the data receiving end;
  • a new socket selection module configured to: when the connection request judging module listens to the connection request of the data sending end, the listening socket reselects a new socket;
  • a socket read data judging processing module configured to judge whether the data is successfully read by the new socket, when the read data is successful, process the data, and write a response packet to the data sending end;
  • the new socket is added to the work queue, and the shape of the new socket is continuously detected. And, when the query to the new socket is readable, notifying the new socket to read data.
  • the embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.
  • a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.
  • FIG. 1 is a flowchart of an implementation of a method for sending network data according to an embodiment of the present invention
  • FIG. 2 is a flowchart of implementing a response packet of a socket reading and receiving end according to an embodiment of the present invention
  • FIG. 3 is a flowchart for implementing detection of read network transmission traffic of a file according to an embodiment of the present invention
  • FIG. 5 is a flowchart of implementing a socket write response packet according to an embodiment of the present invention.
  • FIG. 6 is a flowchart of a method for detecting write network traffic of a file according to an embodiment of the present invention
  • FIG. 7 is a structural diagram of a data transmission system according to an embodiment of the present invention.
  • the embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.
  • a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.
  • the state of the socket is defined as follows:
  • Input and output interface io open After a socket is established, its state becomes io open state; io listener: After a socket is successfully monitored, its state becomes io listener;
  • the socket requests the state before the connection
  • Io idle input / output interface i / o is idle
  • Io idle waiting When the i/o read/write speed is too high, in order to limit the speed and not read and write data, the read/write speed can be read and written after the read/write speed is reduced;
  • Io waits for reading: i/o does not read the data temporarily or waits to read the other party after sending the data Data, or a state in which data is not read because of the speed at which data is restricted;
  • Io waiting to write i/o failed to write data or to control the sending speed without writing data; io test: used to test the status of i/o;
  • Io error the status of the error occurred in i/o
  • Io is shutting down: i/o is performing the shutdown state;
  • Io is put into the release queue: In order to recycle the i/o, after it ends the operation, put it into the queue and wait for the state to be taken again.
  • the flow status of the protocol data is defined as follows:
  • Protocol initialization phase protocol initialization phase
  • the socket has read the network data
  • Reading The socket is reading network data
  • Socket read wait socket does not read data temporarily, the socket in this state will join the work queue, when another thread queries the readable event of the socket, send a notification message to the socket, notify the socket to read Data
  • socket is writing network data
  • Socket write wait This is generally caused by the socket write i / o blockage, the socket in this state should be added to the work area, another thread will query the socket, send a writable notification message when the socket can be written. Then the socket goes to write data again;
  • Processing Processing of protocol data is being analyzed; Processing wait: When a request data is submitted to a new thread for processing, the main thread returns to the processing wait state;
  • step S101 a socket is established, wherein the state of the socket is an open state, and the state of the data protocol is an initialization state.
  • step S102 the sender sends a connection request to the receiver, and the state of the socket is waiting for the connection.
  • step S103 it is judged whether the connection of step S102 is successful, if yes, step S105 is performed, otherwise step S104 is performed.
  • step S104 the above socket is closed, and the program directly returns.
  • step S105 the notification slot slot of the socket is registered.
  • Isocket specifically encapsulates the socket operation
  • the IsocketSlot is specifically used to provide the notified function
  • the Isocket retains the IsocketSlot
  • the IsocketSlot also retains the Isocket, in sending the request.
  • the socket connection is successful
  • the corresponding IsocketSlot is associated with the Isocket, which is the registration process.
  • step S106 protocol data is generated, and the protocol data is stored in a buffer, and the protocol data is prepared. At this time, the state of the protocol data is in a write state, wherein the protocol data includes a status line, a header, and a packet body.
  • step S107 data is written to the receiving end through the socket.
  • step S108 it is judged whether the socket write data is successful, if yes, step S109 is performed; otherwise, step S110 is performed.
  • writing data on the network is written in blocks, for example, every 4K data is sent in one piece.
  • step S109 the socket write data is completed, that is, the data file is sent, the protocol data state is the write data state, and then the socket reads the response of the receiver, and the state of the socket is Read.
  • the socket after the socket reads the response of the protocol data, it indicates that the protocol data is sent, that is, the connection ends; if the read response is unsuccessful, the socket is added to the queue, and the queue is continuously queried for readability. Read the response when it is readable, then close the socket and the entire protocol interaction ends.
  • step S110 the socket write data fails.
  • the socket state is a socket error state
  • the protocol data state is a socket write wait state
  • step S111 the new thread continuously queries the state of the socket in the work queue to determine whether the state of the socket becomes writable. If yes, step S112 is performed; otherwise, step S113 is performed.
  • step S112 the sender sends a writable message to the socket, and returns to the execution step.
  • step S113 it waits until the socket is writable, and step S11 is executed again.
  • TCP Transmission Control Protocol
  • HTTP Hyper Text Transfer Protocol
  • Real Time Real-time streaming protocol
  • RTSP Real-time streaming Protocol
  • custom protocols custom protocols.
  • the socket is allocated to the work area, wherein the processing for the I/O is divided into a plurality of work areas, and each work area has a certain limit on the I/O processed, for example, each work area Only 1024 sockets can be processed at a time.
  • the first workspace handles the listener and the rest of the I/O. If the number of sockets to be processed is large, the work area is increased, and the added work area is processed. Exit when finished; if the number of sockets is small, reduce the workspace.
  • Each workspace is handled by one thread.
  • the default number of queries per window system is 64.
  • the default number of linux is 1024. Under Windows, each socket handles 130 sockets.
  • the work area handles 1024 sockets, and the thread that handles each work area is always running, and each socket of the work area is processed cyclically. This adjustment makes the network concurrent processing capability strong, ensuring speed and efficiency. Among them, the socket is always set in the non-blocking mode.
  • the socket reads the response of the receiving end, that is, the protocol interaction and the file transmission.
  • the protocol interaction includes the request, the processing, and the response. These three steps can indicate the end of the protocol interaction process, and the file transfer process is a cyclic process. File transfer is done by blocking. The transfer of each file is a complete protocol interaction process. The detailed process description is given below:
  • step S201 it is determined whether the response packet of the read receiving end is successful, if yes, step S202 is performed; otherwise, step S203 is performed.
  • step S202 the response packet of the receiving end is read, and the protocol data state is the read state, and the response of the receiving end is processed at the same time.
  • the program is divided into an application layer and an underlying layer.
  • the response is submitted to the application layer for processing, for example, registering a transmission mode, and the client sends a request to the server and the server gives the request.
  • the client reads the response packet of the server, and then submits the response packet to the component that just registered the transmission mode. If the registration is successful, it does not need to be registered again. If the registration is unsuccessful, it will be continuously registered until it succeeds. So far, different response processing methods are different, business requirements are different, and some responses do not need to be processed, but as a protocol interaction process, the entire process is over.
  • the socket state is off, and the protocol data state is also off, and the entire protocol interaction process ends.
  • step S203 the response packet of the receiving end is not read, the socket state changes to a socket error, and the protocol data state changes to a socket read wait. At this time, the socket is added to the work queue.
  • step S204 the new thread continuously queries the status of the socket, that is, determines whether the socket is readable. If yes, step S205 is performed; otherwise, step S206 is performed.
  • step S205 the socket is notified to read the response packet, and the process returns to step S201.
  • step S206 the query continues until the socket is readable.
  • the socket only reads the response packet of the receiver once.
  • the response packet is read multiple times between the sender and the receiver, that is, cyclically read.
  • step S301 it is determined whether the read network transmission traffic exceeds a set value, and if yes, the execution step S302. Otherwise, in the embodiment of the present invention, the determining is to determine whether the file traffic transmitted in the current network exceeds a preset value, because the file transmission is transmitted by using a block, when the block size exceeds a preset value. , that is, the traffic exceeds the predetermined network transmission.
  • step S302 a write interrupt is returned during the file writing process.
  • the protocol data state changes to read data
  • the user waits and the socket state temporarily changes to the idle wait state.
  • step S303 the socket is added to the work queue.
  • step S304 the new thread continuously queries the state of the socket in the work queue, that is, determines whether the socket is readable. If yes, step S305 is performed, otherwise the query is continued.
  • step S305 the socket is notified to read the file data.
  • step S306 in the process of continuously reading the file data by the socket, it is judged whether the read data is successful, and if yes, the reading is continued, otherwise step S308 is performed.
  • step S307 the socket state becomes an error state, and the protocol data state changes to a socket read wait, and the socket is added to the work queue.
  • step S308 another new thread continuously queries the status of the socket, that is, whether the socket is readable. If yes, step S309 is performed, otherwise the query is continued.
  • FIG. 4 is a flowchart showing an implementation process of a method for receiving network data according to an embodiment of the present invention, and the detailed steps are as follows:
  • step S401 a listening socket is established.
  • step S402 it is determined whether the socket monitoring is successful, that is, whether there is a connection request of an IP address and a port, if yes, step S404 is performed; otherwise, step S403 is performed.
  • step S403 the socket is closed and returned.
  • step S404 the listening socket is added to the working queue, and the state of the socket is the listening state.
  • step S405 the new thread continuously queries the listening socket in the work area.
  • step S406 according to the new thread continuously querying, it is determined whether to listen to the connection request of the sender, if yes, step S407 is performed, otherwise, the monitor socket is closed.
  • step S407 the listening socket re-accepts a new socket.
  • the intercepted connection is submitted to the linear queue, and the receiving end specifically opens up a thread to process the connected monitored connection.
  • step S408 it is judged whether the new socket read data of the re-acceptance is successful, and the protocol data state is in the read state, if yes, step S413 is performed, otherwise step S409 is performed.
  • step S409 the new socket reads the data unsuccessfully.
  • the socket state changes to a socket error
  • the protocol data state changes to a socket read error, indicating that the data cannot be read temporarily, and the socket force is injected into the work queue.
  • step S410 the new thread continuously queries the status of the new socket.
  • step S411 it is judged whether the state of the new socket becomes readable, if yes, step S412 is performed, otherwise the query is continued, and the step is returned.
  • step S412 the receiving end sends a readable notification message to the new socket, and returns to step S408.
  • step S413 after the data is read, the protocol data state changes to the read state, and the analysis processing protocol data is started. At this time, the protocol data state changes to the processing state.
  • step S414 the receiving end writes the response data, and the socket status side is writing.
  • the receiving end write response data includes two cases, that is, normal protocol interaction and file transmission.
  • the protocol interaction includes request, processing, and response, and the three steps can be represented.
  • the protocol interaction process ends, and the file transfer process is a cyclic process. File transfer is done by blocking. The transfer of each file is a complete protocol interaction process.
  • step S501 it is determined whether the write response packet is successful, if yes, step S502 is performed, otherwise step S503 is performed.
  • step S502 the response packet is successfully written, and the protocol data state is in the write state, and the socket is closed. After processing, the socket status is off, and the protocol data status is also off. The protocol interaction process ends. If it is a file transfer, the socket can only be closed after all the block file transfers are completed.
  • step S503 if the response to the packet write fails, the socket state changes to a socket error, and the protocol data state changes to a socket write wait. At this time, the socket is added to the work queue.
  • step S504 the new thread continuously queries the state of the socket.
  • step S505 it is determined whether the socket is writable, if yes, step S506 is performed, otherwise step S507 is performed.
  • step S506 the socket is notified to write the response packet, and the process returns to step S501.
  • step S507 the query continues until the socket is writable.
  • the receiving end writes a response packet to the data sending end multiple times, and each time the file is sent, the file is written in response, wherein the detailed flow of detecting whether the network traffic exceeds the set value is as follows: Said:
  • step S601 it is judged whether the flow rate of the network of the file data exceeds the set value, if yes, step S602 is performed, otherwise, it ends.
  • step S602 a read interrupt is returned during the process of reading the file.
  • the protocol data state changes to the write data user waits, and the socket state temporarily becomes the idle wait state.
  • step S603 the socket is added to the work queue.
  • step S604 the new thread continuously queries the status of the socket in the work queue, that is, determines whether the socket is writable, and if yes, step S605 is performed, otherwise the query is continued.
  • step S605 the socket is notified to write the file data.
  • step S606 in the process of continuously writing the file data by the socket, it is judged whether the write data is successful, and if yes, the reading is continued, otherwise step S607 is performed.
  • step S607 the socket state becomes an error state, and the protocol data state changes to a socket write wait, and the socket is added to the work queue.
  • step S608 another new thread continuously queries the status of the socket, that is, whether the socket is writable, and if yes, step S609 is performed, otherwise the query is continued.
  • FIG. 7 is a structural diagram of a data transmission system according to an embodiment of the present invention. For convenience of description, only parts related to the embodiment of the present invention are shown, wherein the data transmission system 1 and the data receiving system 2 are placed in a software unit of the terminal. , hardware unit or hardware and software unit.
  • the data transmission system 1 includes a socket establishment module 11, a connection request transmission module 12, a notification slot registration module 13, and a socket write data judgment processing module 14, wherein:
  • the socket establishing module 11 establishes a socket; the connection request sending module 12 sends a network connection request; When it is determined that the connection is successful, the slot registration module 13 is notified to register the notification slot of the socket; the socket write data judgment processing module 14 determines whether the data is successfully written by the socket, and when the data is successfully written, Reading the response packet of the data receiving end; when the writing data is unsuccessful, the socket is added to the working queue, and the state of the socket is continuously detected, and when the socket is writable, the socket is notified to be writable data.
  • the socket write data processing judging module 14 further includes a read response packet judging module 141, a read response packet processing module 142, and a read response packet judging processing module 143, wherein:
  • the read response packet judgment module 141 determines whether the response packet of the read receiving end is successful; when the read response packet of the receiving end succeeds, the read response packet processing module 142 processes the response packet; when the response packet of the receiving end is unsuccessful, The read response packet judgment processing module 143 adds the socket to the work queue, and continuously detects the state of the socket. When the socket is readable, the response packet of the data receiving end is read.
  • the socket write data judgment processing module 14 further includes a read network traffic judgment module 144 and a read traffic processing module 145.
  • the read network traffic judgment module 144 determines whether the network transmission traffic of the file data exceeds a preset. Value; when the network transmission traffic of the file data exceeds a preset value, the read traffic processing module 145 returns a write interrupt, adds the socket to the work queue, and determines the state of the query socket. When the socket is readable, the socket is notified. Read file data.
  • the data receiving system 2 includes a listening socket establishment determining module 21, a connection request judging module 22, a new socket selecting module 23, and a socket reading data judging processing module 24, wherein:
  • the listening socket establishment determining module 21 establishes a listening socket and determines whether the socket monitoring is successful; the connection request determining module 22 determines whether the listening socket listens to the network connection request; when the connection is successful, the new socket selecting module 23 monitors The socket will re-accept - a new socket; the socket read data judgment processing module 24 determines whether the data is successfully read by the new socket, and when the data is successfully read, the request packet of the data sender is read; When the data is unsuccessful, the new socket is added to the work queue, and the state of the new socket is continuously detected. When the new socket is readable, the new socket readable data is notified.
  • the socket read data judgment processing module 24 includes a write response packet judgment module 241, a write response packet processing module 242, and a write response packet judgment processing module 243, wherein:
  • the write response packet judgment module 241 determines whether the write response packet is successful; when the write response packet succeeds, the write back The packet processing module 242 closes the socket; the write response packet judgment processing module 243 adds the new socket to the work queue when the write response packet is unsuccessful, and continuously detects the state of the new socket, when the new set When the word is writable, write the response packet.
  • the socket read data judging processing module 24 further includes a write network traffic judging module 244 and a write traffic processing module 245, where:
  • the write network traffic judgment module 244 determines whether the network transmission traffic of the file data exceeds a preset value; when the network transmission traffic of the file data exceeds a preset value, the write traffic processing module returns a read interrupt, and adds the socket to the work. In the queue, and determine the state of the socket, when the socket is writable, the socket is notified to send the file data.
  • the embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.
  • a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow.

Landscapes

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

Abstract

A method and system for transmitting data are disclosed. The method includes the following steps of: sending a network connection request to a data receiving terminal; after the connection is successful and a notice slot of the pre-established socket is registered, judging whether it is successful to write data into the data receiving terminal through the socket or not, when it is successful reading the response package of the data receiving terminal, and when it is unsuccessful adding the socket into a work queue, and notifying the socket to write the data into the data receiving terminal when it is inquired that the socket is writable. In the embodiments of the invention, the state machine is built for the socket through general inquiring mechanism, and the socket performs the data circulation according to the state machine, and a notice mechanism is built for the socket to notice the state of data circulation of the socket in time and exactly, so the network protocol and the network connection are disposed effectively in the case of the large network subsequent quantity.

Description

一种数据的传输方法及系统  Data transmission method and system
本申请要求于 2007 年 9 月 7 日提交中国专利局、 申请号为 200710076929.2、 发明名称为"一种数据的传输方法及系统 "的中国专利申请的 优先权, 其全部内容通过引用结合在本申请中。  The present application claims priority to Chinese Patent Application No. 200710076929.2, entitled "A Data Transmission Method and System", filed on September 7, 2007, the entire contents of which is incorporated herein by reference. in.
技术领域 Technical field
本发明属于网络通信领域, 尤其涉及一种数据的传输方法及系统。  The invention belongs to the field of network communication, and in particular relates to a data transmission method and system.
背景技术 Background technique
在网络服务器系统中 ,对于客户端的连接请求,其处理方式采用两种模型: 一种是接收端采用迭代服务器模型,依次处理客户端的请求; 另一种是接收端 采用并发服务器模型 ,对于每个客户请求产生一个进程去处理。接收端采用并 发服务器模型,预先派生一些子进程处理客户请求;接收端采用并发服务器模 型, 对于每个客户产生一个线程去处理; 接收端采用并发服务器模型, 预先派 生一些线程去处理。  In the network server system, there are two models for the client's connection request: one is that the receiver uses the iterative server model to process the client's request in turn; the other is that the receiver uses the concurrent server model for each The client requests a process to process. The receiving end adopts the concurrent server model, and some sub-processes are pre-derived to process client requests; the receiving end adopts a concurrent server model, and one thread is generated for each client to process; the receiving end adopts a concurrent server model, and some threads are pre-derived for processing.
现有技术一般都是接收端采用并发服务器模型,预先派生一些线程去处理 客户端请求,每当有一个客户端请求过来, 就将这个请求提交到一个线程池里 面, 直到这个请求处理完为止。  In the prior art, the receiving end generally adopts a concurrent server model, and some threads are pre-derived to process client requests. Whenever a client requests, the request is submitted to a thread pool until the request is processed.
现有技术对于套接字中间状态、协议的执行状态以及数据执行状态的流转 没有划分或者划分的不合理或者没有引入这种机制 ,并且套接字没有采用通知 机制或者不完善, 当网络事件发生时, 不能及时、 准确地通知应用层。  The prior art does not divide or divide the execution of the intermediate state of the socket, the execution state of the protocol, and the execution state of the data, or introduces such a mechanism, and the socket does not adopt a notification mechanism or is imperfect, when a network event occurs. When the application layer is not notified in a timely and accurate manner.
发明内容 Summary of the invention
本发明实施例的目的在于提供一种数据传输方法及系统,旨在解决现有技 术中网络数据传输并发量大, 当网络事件发生时, 不能及时准确通知应用层的 问题。  The purpose of the embodiments of the present invention is to provide a data transmission method and system, which aims to solve the problem that the network data transmission in the prior art is large and the application layer cannot be accurately and timely notified when a network event occurs.
本发明实施例是这样实现的,一种数据的发送方法,所述方法包括下述步 骤:  The embodiment of the present invention is implemented by the method for sending data, and the method includes the following steps:
向数据接收端发送网络连接请求;  Sending a network connection request to the data receiving end;
当连接成功并为预先建立的套接字注册通知插槽后 ,判断通过所述套接字 向数据接收端写数据是否成功, 当写数据成功时,读取所述数据接收端的回应 包; 当写数据不成功时, 将所述套接字加入工作队列, 当查询到所述套接字可 写时, 通知所述套接字向所述数据接收端写数据。 After the connection is successful and the notification slot is registered for the pre-established socket, it is judged whether the data is successfully written to the data receiving end by the socket, and when the data is successfully written, the response packet of the data receiving end is read; When the write data is unsuccessful, the socket is added to the work queue, and when the socket is queried, When writing, the socket is notified to write data to the data receiving end.
本发明实施例的另一目的在于提供一种数据的接收方法,所述方法包括下 述步骤:  Another object of the embodiments of the present invention is to provide a method for receiving data, the method comprising the following steps:
当通过预先建立的监听套接字监听到数据发送端的连接请求时,所述监听 套接字重新选择一个新套接字;  When the connection request of the data sender is monitored through a pre-established listening socket, the listening socket reselects a new socket;
判断通过所述新套接字读数据是否成功,当读数据成功时,处理所述数据, 并向所述数据发送端写回应包; 当读取数据不成功时,将所述新套接字加入工 作队列, 并不断检测所述新套接字的状态, 当查询到所述新套接字可读时, 通 知所述新套接字读数据。  Determining whether the data is successfully read by the new socket, processing the data when the data is successful, and writing a response packet to the data sending end; when the reading data is unsuccessful, the new socket is Joining the work queue, and continuously detecting the status of the new socket, and notifying the new socket to read data when the new socket is readable.
本发明实施例的另一目的在于提供一种数据发送系统, 所述系统包括: 套接字建立模块, 用于建立套接字;  Another object of the present invention is to provide a data sending system, where the system includes: a socket establishing module, configured to establish a socket;
连接请求发送模块, 用于向数据接收端发送网络连接请求;  a connection request sending module, configured to send a network connection request to the data receiving end;
通知插槽注册模块, 用于当连接成功时, 注册所述套接字的通知插槽; 以 及  Notifying a slot registration module, for registering a notification slot of the socket when the connection is successful; and
套接字写数据判断处理模块,用于在所述通知插槽注册模块注册所述套接 字的通知插槽后,判断通过所述套接字向数据接收端写数据是否成功, 当写数 据成功时, 读取所述数据接收端的回应包; 当写数据不成功时, 将所述套接字 加入工作队列, 当查询到所述套接字可写时,通知所述套接字向所述数据接收 端写数据。  a socket write data judging processing module, configured to determine, after the notification slot registration module registers the notification slot of the socket, whether the data is successfully written to the data receiving end by the socket, when writing data If successful, the response packet of the data receiving end is read; when the writing data is unsuccessful, the socket is added to the working queue, and when the socket is readable, the socket is notified to the The data receiving end writes data.
本发明实施例的另一目的在于提供一种数据接收系统, 所述系统包括: 监听套接字建立判断模块, 用于建立监听套接字, 并判断所述套接字监听 是否成功;  Another object of the present invention is to provide a data receiving system, where the system includes: a listening socket establishment determining module, configured to establish a listening socket, and determine whether the socket monitoring is successful;
连接请求判断模块, 用于当所述监听套接字监听成功后, 判断所述监听套 接字是否监听到数据接收端的连接请求;  a connection request judging module, configured to determine, after the monitoring socket is successfully monitored, whether the listening socket listens to a connection request of the data receiving end;
新套接字选择模块,用于当所述连接请求判断模块监听到数据发送端的连 接请求时, 所述监听套接字重新选择一个新套接字; 以及  a new socket selection module, configured to: when the connection request judging module listens to the connection request of the data sending end, the listening socket reselects a new socket;
套接字读取数据判断处理模块,用于判断通过所述新套接字读数据是否成 功, 当读数据成功时, 处理所述数据, 并向所述数据发送端写回应包; 当读取 数据不成功时,将所述新套接字加入工作队列, 并不断检测所述新套接字的状 态, 当查询到所述新套接字可读时, 通知所述新套接字读数据。 a socket read data judging processing module, configured to judge whether the data is successfully read by the new socket, when the read data is successful, process the data, and write a response packet to the data sending end; When the data is unsuccessful, the new socket is added to the work queue, and the shape of the new socket is continuously detected. And, when the query to the new socket is readable, notifying the new socket to read data.
本发明实施例通过一般的查询机制,对套接字建立状态机,套接字根据状 态机进行数据流转, 以及对套接字建立一个通知机制, 实现及时准确地通知套 接字数据流转的状态,这样在网络并发量很大的情况下,有效地处理了网络协 议以及网络连接。  The embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow. In this way, network protocols and network connections are effectively handled in the case of a large amount of network concurrency.
附图说明 DRAWINGS
图 1是本发明实施例提供的网络数据的发送方法的实现流程图;  1 is a flowchart of an implementation of a method for sending network data according to an embodiment of the present invention;
图 2是本发明实施例提供的 socket读取接收端的回应包实现流程图; 图 3是本发明实施例提供的文件的读网络传输流量的检测实现流程图; 图 4是本发明实施例提供的网络数据的接收方法的实现流程图;  2 is a flowchart of implementing a response packet of a socket reading and receiving end according to an embodiment of the present invention; FIG. 3 is a flowchart for implementing detection of read network transmission traffic of a file according to an embodiment of the present invention; Flow chart for implementing the method for receiving network data;
图 5是本发明实施例提供的 socket写回应包实现流程图;  FIG. 5 is a flowchart of implementing a socket write response packet according to an embodiment of the present invention;
图 6是本发明实施例提供的文件的写网络流量的检测实现流程图; 图 7是本发明实施例提供的数据传输系统的结构图。  FIG. 6 is a flowchart of a method for detecting write network traffic of a file according to an embodiment of the present invention; FIG. 7 is a structural diagram of a data transmission system according to an embodiment of the present invention.
具体实施方式 detailed description
为了使本发明的目的、技术方案及优点更加清楚明白, 以下结合附图及实 施例, 对本发明进行进一步详细说明。 应当理解, 此处所描述的具体实施例仅 仅用以解释本发明, 并不用于限定本发明。  The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
本发明实施例通过一般的查询机制,对套接字建立状态机,套接字根据状 态机进行数据流转, 以及对套接字建立一个通知机制, 实现及时准确地通知套 接字数据流转的状态,这样在网络并发量很大的情况下,有效地处理了网络协 议以及网络连接。  The embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow. In this way, network protocols and network connections are effectively handled in the case of a large amount of network concurrency.
在本发明实施例中, 套接字 (socket ) 的状态的定义如下:  In the embodiment of the present invention, the state of the socket is defined as follows:
输入输出接口 io打开:一个套接字建立之后,其状态就变为 io打开状态; io监听: 一个套接字监听成功之后, 其状态就变为 io监听;  Input and output interface io open: After a socket is established, its state becomes io open state; io listener: After a socket is successfully monitored, its state becomes io listener;
io等待连接: 该套接字请求连接之前的状态;  Io wait for the connection: the socket requests the state before the connection;
io空闲: 输入 /输出接口 i/o处于空闲状态;  Io idle: input / output interface i / o is idle;
io空闲等待: i/o读写速度过高时暂时为了限制速度而不读写数据的状态, 当读写速度降低之后即可进行读写;  Io idle waiting: When the i/o read/write speed is too high, in order to limit the speed and not read and write data, the read/write speed can be read and written after the read/write speed is reduced;
io等待读: i/o暂时没有读到数据或者本方发送数据之后等待读取对方的 数据 , 或者由于限制数据的接收速度而没有读取到数据的状态; Io waits for reading: i/o does not read the data temporarily or waits to read the other party after sending the data Data, or a state in which data is not read because of the speed at which data is restricted;
io等待写: i/o写数据失败或者为了控制发送速度而没有写数据的状态; io测试: 用来测试 i/o的状态;  Io waiting to write: i/o failed to write data or to control the sending speed without writing data; io test: used to test the status of i/o;
io等待关闭: i/o即将关闭的状态;  Io waits for the shutdown: i/o is about to be closed;
io错误: i/o发生错误的状态;  Io error: the status of the error occurred in i/o;
io正在关闭: i/o正在执行关闭操作的状态;  Io is shutting down: i/o is performing the shutdown state;
io关闭结束: i/o已经关闭的状态;  Io closed: i/o has been closed;
io被放入释放队列: 为了循环利用该 i/o, 在其结束操作后, 将其放入队 列, 等待再次被取用的状态。  Io is put into the release queue: In order to recycle the i/o, after it ends the operation, put it into the queue and wait for the state to be taken again.
而协议数据的流转状态的定义如下:  The flow status of the protocol data is defined as follows:
初始化: 协议初始化阶段;  Initialization: protocol initialization phase;
读: socket已经读取完了网络数据;  Read: The socket has read the network data;
正在读: socket正在读取网络数据;  Reading: The socket is reading network data;
读数据用户等待: 当从网络上读取到数据之后, 就要保存数据到緩冲或者 写文件, 这个状态一般用来限制速度, 当速度大于某一个阀值的时候, 就让写 文件处于等待状态, 直到速度下降再写文件;  Read data user waits: After reading data from the network, it is necessary to save the data to the buffer or write the file. This state is generally used to limit the speed. When the speed is greater than a certain threshold, the write file is waiting. State, until the speed drops and then write the file;
socket读等待: socket暂时没有读到数据, 处在这个状态的 socket会加入 到工作队列,在另外一个线程查询到该 socket的可读事件时,向该 socket发送 通知消息 , 通知该 socket去读取数据;  Socket read wait: socket does not read data temporarily, the socket in this state will join the work queue, when another thread queries the readable event of the socket, send a notification message to the socket, notify the socket to read Data
写: socket已经写完了网络数据;  Write: socket has finished writing network data;
正在写: socket正在写网络数据;  Writing: socket is writing network data;
写数据用户等待: 这个状态是为了限制速度, 要写数据的时候, 首先要从 文件或者緩冲去取数据, 当发送速度过快时, 为了限制速度, 就会让用户暂时 取不到数据, 直到速度降下来再取数据;  Write data user wait: This state is to limit the speed. When writing data, firstly, the data should be fetched from the file or buffer. When the sending speed is too fast, in order to limit the speed, the user will not be able to temporarily obtain the data. Until the speed drops, take the data;
socket写等待: 这一般是由于发生 socket写 i/o堵塞造成的, 处于这个状 态的 socket要加入到工作区, 另外一个线程会查询该 socket, 在该 socket可写 的时候发送可写通知消息 , 然后该 socket再去写数据;  Socket write wait: This is generally caused by the socket write i / o blockage, the socket in this state should be added to the work area, another thread will query the socket, send a writable notification message when the socket can be written. Then the socket goes to write data again;
处理: 协议数据分析处理完毕;  Processing: The protocol data analysis is completed;
正在处理: 正在分析处理协议数据; 处理等待: 将一个请求数据提交到一个新的线程中去处理时, 主线程返回 处理等待状态; Processing: Processing of protocol data is being analyzed; Processing wait: When a request data is submitted to a new thread for processing, the main thread returns to the processing wait state;
错误: socket错误时的处理状态;  Error: Processing status when socket error occurs;
准备关闭: 当协议数据全部处理完毕之后, 将状态置为准备关闭状态; 关闭: 协议关闭之后准备关闭 socket的状态。 步骤如下所述:  Ready to close: When the protocol data is completely processed, the state is set to be ready to be closed; Close: The state of the socket is ready to be closed after the protocol is closed. The steps are as follows:
在步骤 S101中, 建立一个 socket, 其中该 socket的状态为打开状态, 数 据协议状态为初始化状态。  In step S101, a socket is established, wherein the state of the socket is an open state, and the state of the data protocol is an initialization state.
在步骤 S102中, 发送端向接收端发送连接请求, 此时 socket的状态为等 待连接。  In step S102, the sender sends a connection request to the receiver, and the state of the socket is waiting for the connection.
在步骤 S103中, 判断步骤 S102的连接是否成功, 是则执行步骤 S105 , 否则执行步骤 S104。  In step S103, it is judged whether the connection of step S102 is successful, if yes, step S105 is performed, otherwise step S104 is performed.
在步骤 S104中, 关闭上述 socket, 程序直接返回。  In step S104, the above socket is closed, and the program directly returns.
在步骤 S105中, 注册 socket的通知插槽 slot。  In step S105, the notification slot slot of the socket is registered.
在本发明实施例中, 在程序中有 2个类为 Isocket与 IsocketSlot, Isocket 专门封装了 socket操作, IsocketSlot专门用来提供被通知功能, Isocket保留有 IsocketSlot, IsocketSlot也保留有 Isocket, 在发送请求的时候, 如果 socket连 接成功, 那么就将相应的 IsocketSlot与本 Isocket关联起来, 这就是注册的过 程。  In the embodiment of the present invention, there are two classes in the program, Isocket and IsocketSlot. The Isocket specifically encapsulates the socket operation, the IsocketSlot is specifically used to provide the notified function, the Isocket retains the IsocketSlot, and the IsocketSlot also retains the Isocket, in sending the request. At the time, if the socket connection is successful, then the corresponding IsocketSlot is associated with the Isocket, which is the registration process.
在步骤 S106中, 生成协议数据, 并将该协议数据存储到緩冲区, 准备发 送协议数据,此时协议数据的状态为正在写状态,其中该协议数据包括状态行、 头部以及包体。  In step S106, protocol data is generated, and the protocol data is stored in a buffer, and the protocol data is prepared. At this time, the state of the protocol data is in a write state, wherein the protocol data includes a status line, a header, and a packet body.
在步骤 S107中, 通过 socket向接收端写数据。  In step S107, data is written to the receiving end through the socket.
在步骤 S108中, 判断 socket写数据是否成功, 是则执行步骤 S109; 否则 执行步骤 S110。 其中, 在网络上写数据是分块来写的, 例如每 4K数据为一块 进行发送。  In step S108, it is judged whether the socket write data is successful, if yes, step S109 is performed; otherwise, step S110 is performed. Among them, writing data on the network is written in blocks, for example, every 4K data is sent in one piece.
在步骤 S109中, socket写数据完成, 即数据文件发送完毕, 协议数据状 态为写数据状态, 然后, socket读取接收端的回应, 此时 socket的状态为正在 读。 In step S109, the socket write data is completed, that is, the data file is sent, the protocol data state is the write data state, and then the socket reads the response of the receiver, and the state of the socket is Read.
在本发明实施例中, socket读完协议数据的回应后, 表示协议数据发送结 束, 即连接结束; 如果读取回应不成功, 那么将该 socket加入到队列, 并不断 查询该队列是否可读, 可读时再读取回应, 然后关闭 socket, 整个协议交互结 束。  In the embodiment of the present invention, after the socket reads the response of the protocol data, it indicates that the protocol data is sent, that is, the connection ends; if the read response is unsuccessful, the socket is added to the queue, and the queue is continuously queried for readability. Read the response when it is readable, then close the socket and the entire protocol interaction ends.
在步骤 S110中, socket写数据失败, 此时 socket状态为 socket错误状态, 而协议数据状态为 socket写等待状态, 同时将 socket加入到某个工作队列。  In step S110, the socket write data fails. At this time, the socket state is a socket error state, and the protocol data state is a socket write wait state, and the socket is added to a work queue.
在步骤 S111中, 新线程不断查询上述工作队列中的 socket的状态, 判断 socket的状态是否变为可写, 是则执行步骤 S112, 否则执行步骤 S113。  In step S111, the new thread continuously queries the state of the socket in the work queue to determine whether the state of the socket becomes writable. If yes, step S112 is performed; otherwise, step S113 is performed.
在步骤 S112 中, 发送端向上述 socket发送可写消息, 并返回执行步骤 In step S112, the sender sends a writable message to the socket, and returns to the execution step.
S108, 在本发明实施例中, 这个循环过程是一直存在的, 直到数据文件发送完 毕。 S108, in the embodiment of the present invention, the loop process is always present until the data file is sent.
在步骤 S113中, 等待, 直到 socket可写状态, 并再次执行步骤 Sl l l。 在本发明实施例中,数据传输过程是采用基于传输控制协议( Transmission Control Protocol , TCP )的协议 ,该 TCP协议主要是超文本传输协议( Hyper Text Transfer Protocol, HTTP )、 实时流协议( Real Time Streaming Protocol, RTSP ) 以及自定义协议。  In step S113, it waits until the socket is writable, and step S11 is executed again. In the embodiment of the present invention, the data transmission process is based on a Transmission Control Protocol (TCP) protocol, which is mainly a Hyper Text Transfer Protocol (HTTP), a real-time streaming protocol (Real Time). Streaming Protocol, RTSP) and custom protocols.
在本发明实施例中, 将套接字分配到工作区中, 其中对于 I/O的处理分为 很多工作区, 每一个工作区处理的 I/O有一定的限制, 例如每个工作区每次只 能处理 1024个套接字, 目前由第一个工作区处理监听和其余剩余的 I/O,如果 要处理的套接字数目多了, 就增加工作区,增加的工作区在工作处理完成之后 会退出; 如果套接字数目少了, 就减少工作区。 每个工作区由一个线程处理, 一般 windows系统默认每次查询的数目是 64个, linux下默认的数目是 1024 个, 在 windows下每个工作区处理 130个套接字, 在 linux下每个工作区处理 1024 个套接字, 处理每个工作区的线程一直都在运行, 循环处理该工作区的 每一个套接字, 这样调整使得网络并发处理能力很强, 保证了速度和效率。 其 中, 套接字一直设置处在非堵塞模式。  In the embodiment of the present invention, the socket is allocated to the work area, wherein the processing for the I/O is divided into a plurality of work areas, and each work area has a certain limit on the I/O processed, for example, each work area Only 1024 sockets can be processed at a time. Currently, the first workspace handles the listener and the rest of the I/O. If the number of sockets to be processed is large, the work area is increased, and the added work area is processed. Exit when finished; if the number of sockets is small, reduce the workspace. Each workspace is handled by one thread. Generally, the default number of queries per window system is 64. The default number of linux is 1024. Under Windows, each socket handles 130 sockets. The work area handles 1024 sockets, and the thread that handles each work area is always running, and each socket of the work area is processed cyclically. This adjustment makes the network concurrent processing capability strong, ensuring speed and efficiency. Among them, the socket is always set in the non-blocking mode.
作为本发明的一个实施例, socket读取接收端的回应存在两种情况, 即协 议交互与文件传输, 在本发明实施例中, 协议交互包括请求、 处理以及回应, 这三个步骤即可表示该协议交互过程结束,而文件传输的过程是一个循环的过 程, 文件传输是通过分块来完成的,每一块文件的传输都是一个完整的协议交 互的过程。 下述给出详细流程描述: As an embodiment of the present invention, there are two situations in which the socket reads the response of the receiving end, that is, the protocol interaction and the file transmission. In the embodiment of the present invention, the protocol interaction includes the request, the processing, and the response. These three steps can indicate the end of the protocol interaction process, and the file transfer process is a cyclic process. File transfer is done by blocking. The transfer of each file is a complete protocol interaction process. The detailed process description is given below:
在步骤 S201中,判断读取接收端的回应包是否成功,是则执行步骤 S202, 否则执行步骤 S203。  In step S201, it is determined whether the response packet of the read receiving end is successful, if yes, step S202 is performed; otherwise, step S203 is performed.
在步骤 S202中,读取到了接收端的回应包,此时协议数据状态为读状态, 同时处理接收端的回应。  In step S202, the response packet of the receiving end is read, and the protocol data state is the read state, and the response of the receiving end is processed at the same time.
在本发明实施例中, 程序分为应用层和底层, 在底层读取到回应之后, 将 回应提交到应用层处理, 例如注册一种传输方式,在客户端向服务端发送请求 而服务端给予回应之后,客户端读取到了服务端的回应包, 然后将回应包提交 到刚才注册传输方式的组件, 如果注册成功, 则不需要再注册了, 如果注册不 成功, 则会不断地注册, 直到成功为止, 当然不同的回应处理方式不同, 业务 需求也不一样, 有的回应不需要处理, 但作为一个协议的交互过程, 整个流程 要结束。  In the embodiment of the present invention, the program is divided into an application layer and an underlying layer. After the bottom layer reads the response, the response is submitted to the application layer for processing, for example, registering a transmission mode, and the client sends a request to the server and the server gives the request. After the response, the client reads the response packet of the server, and then submits the response packet to the component that just registered the transmission mode. If the registration is successful, it does not need to be registered again. If the registration is unsuccessful, it will be continuously registered until it succeeds. So far, different response processing methods are different, business requirements are different, and some responses do not need to be processed, but as a protocol interaction process, the entire process is over.
处理完毕之后, socket状态为关闭, 而协议数据状态也为关闭状态, 整个 协议交互过程结束。  After processing, the socket state is off, and the protocol data state is also off, and the entire protocol interaction process ends.
在步骤 S203 中, 没有读取到接收端的回应包, socket状态变化为 socket 错误, 协议数据状态变化为 socket读等待, 此时, 将 socket加入到工作队列。  In step S203, the response packet of the receiving end is not read, the socket state changes to a socket error, and the protocol data state changes to a socket read wait. At this time, the socket is added to the work queue.
在步骤 S204中, 新线程不断查询该 socket的状态, 即判断 socket是否可 读, 是则执行步骤 S205 , 否则执行步骤 S206。  In step S204, the new thread continuously queries the status of the socket, that is, determines whether the socket is readable. If yes, step S205 is performed; otherwise, step S206 is performed.
在步骤 S205中 , 通知 socket读取回应包, 同时返回执行步骤 S201。  In step S205, the socket is notified to read the response packet, and the process returns to step S201.
在步骤 S206中, 继续查询, 直到 socket可读。  In step S206, the query continues until the socket is readable.
如果上述的网络连接是正常的协议交互,那么 socket只读取一次接收端的 回应包。  If the above network connection is a normal protocol interaction, then the socket only reads the response packet of the receiver once.
如果上述连接是文件传输, 则发送端与接收端之间多次读取回应包, 即循 环读取。  If the above connection is a file transfer, the response packet is read multiple times between the sender and the receiver, that is, cyclically read.
在本发明实施例中, 对于网络连接为文件传输的情况, 如图 3所述, 对读 取网络的流量是否超过设定值进行检测 , 其详细步骤如下所述:  In the embodiment of the present invention, in the case that the network connection is a file transmission, as shown in FIG. 3, whether the traffic of the read network exceeds a set value is detected, and the detailed steps are as follows:
在步骤 S301中, 判断读取网络传输流量是否超过设定值, 是则执行步骤 S302, 否则结束, 在本发明实施例中, 该判断即是判断当前网络中传输的文件 流量是否超过预先设定值, 因为文件传输是分块来传输的, 当分块大小超过预 先设定值时, 即为超出预定网络传输流量。 In step S301, it is determined whether the read network transmission traffic exceeds a set value, and if yes, the execution step S302. Otherwise, in the embodiment of the present invention, the determining is to determine whether the file traffic transmitted in the current network exceeds a preset value, because the file transmission is transmitted by using a block, when the block size exceeds a preset value. , that is, the traffic exceeds the predetermined network transmission.
在步骤 S302中, 在写文件过程中返回写中断, 此时协议数据状态变化为 读数据用户等待, socket状态暂时变为空闲等待状态。  In step S302, a write interrupt is returned during the file writing process. At this time, the protocol data state changes to read data, the user waits, and the socket state temporarily changes to the idle wait state.
在步骤 S303中, 将 socket加入到工作队列中。  In step S303, the socket is added to the work queue.
在步骤 S304中, 新线程不断查询上述工作队列中的 socket的状态, 即判 断上述 socket是否可读, 是则执行步骤 S305 , 否则执行继续查询。  In step S304, the new thread continuously queries the state of the socket in the work queue, that is, determines whether the socket is readable. If yes, step S305 is performed, otherwise the query is continued.
在步骤 S305中, 通知 socket读取文件数据。  In step S305, the socket is notified to read the file data.
在步骤 S306中, 在 socket不断读取文件数据的过程中, 判断读取数据是 否成功, 是则继续读取, 否则执行步骤 S308。  In step S306, in the process of continuously reading the file data by the socket, it is judged whether the read data is successful, and if yes, the reading is continued, otherwise step S308 is performed.
在步骤 S307中, socket状态变为错误状态, 协议数据状态变化为 socket 读等待 , 将该 socket加入到工作队列。  In step S307, the socket state becomes an error state, and the protocol data state changes to a socket read wait, and the socket is added to the work queue.
在步骤 S308中,另外一个新线程不断查询该 socket的状态,即判断 socket 是否可读, 是则执行步骤 S309, 否则继续查询。  In step S308, another new thread continuously queries the status of the socket, that is, whether the socket is readable. If yes, step S309 is performed, otherwise the query is continued.
在步骤 S309中, 通知该 socket读取数据, 如此反复直到文件读完为止。 通过上述的实现流程就有效的控制了网络流量, 实现文件数据的传输。 图 4示出了本发明实施例提供的网络数据的接收方法的实现流程,其详细 步骤如下所述:  In step S309, the socket is notified to read the data, and so on until the file is read. Through the above implementation process, network traffic is effectively controlled, and file data transmission is realized. FIG. 4 is a flowchart showing an implementation process of a method for receiving network data according to an embodiment of the present invention, and the detailed steps are as follows:
在步骤 S401中, 建立一监听 socket。  In step S401, a listening socket is established.
在步骤 S402中, 判断 socket监听是否成功, 即是否有某一个 ip地址和端 口的连接请求, 是则执行步骤 S404, 否则执行步骤 S403。  In step S402, it is determined whether the socket monitoring is successful, that is, whether there is a connection request of an IP address and a port, if yes, step S404 is performed; otherwise, step S403 is performed.
在步骤 S403中, 关闭该 socket并返回。  In step S403, the socket is closed and returned.
在步骤 S404中, 将监听 socket加入到工作队列, 该 socket的状态为监听 状态。  In step S404, the listening socket is added to the working queue, and the state of the socket is the listening state.
在步骤 S405中, 新线程不断查询工作区中的监听 socket。  In step S405, the new thread continuously queries the listening socket in the work area.
在步骤 S406中, 根据上述新线程不断查询, 判断是否监听到发送端的连 接请求, 是则执行步骤 S407, 否则结束, 关闭该监听 socket。  In step S406, according to the new thread continuously querying, it is determined whether to listen to the connection request of the sender, if yes, step S407 is performed, otherwise, the monitor socket is closed.
在步骤 S407中 , 监听 socket重新 accept—个新的 socket。 在本发明实施例中,将监听到的连接提交到线性队列中,接收端专门开辟 一线程处理监听到的该连接。 In step S407, the listening socket re-accepts a new socket. In the embodiment of the present invention, the intercepted connection is submitted to the linear queue, and the receiving end specifically opens up a thread to process the connected monitored connection.
在步骤 S408中, 判断重新 accept的新 socket读取数据是否成功, 此时协 议数据状态是正在读状态, 是则执行步骤 S413 , 否则执行步骤 S409。  In step S408, it is judged whether the new socket read data of the re-acceptance is successful, and the protocol data state is in the read state, if yes, step S413 is performed, otherwise step S409 is performed.
在步骤 S409中 ,新 socket读取数据不成功 ,此时该 socket状态变化为 socket 错误, 协议数据状态变化为 socket读错误, 表明暂时读不到数据, 同时将该 socket力 p入到工作队列中。  In step S409, the new socket reads the data unsuccessfully. At this time, the socket state changes to a socket error, and the protocol data state changes to a socket read error, indicating that the data cannot be read temporarily, and the socket force is injected into the work queue. .
在步骤 S410中, 新线程不断查询新 socket的状态。  In step S410, the new thread continuously queries the status of the new socket.
在步骤 S411中,判断新 socket的状态是否变为可读,是则执行步骤 S412, 否则继续查询, 并返回该步骤。  In step S411, it is judged whether the state of the new socket becomes readable, if yes, step S412 is performed, otherwise the query is continued, and the step is returned.
在步骤 S412中, 接收端向新 socket发送可读的通知消息, 并返回执行步 骤 S408。  In step S412, the receiving end sends a readable notification message to the new socket, and returns to step S408.
在步骤 S413中, 读取数据完毕之后, 协议数据状态变化为读状态, 开始 分析处理协议数据, 此时协议数据状态变化为正在处理状态。  In step S413, after the data is read, the protocol data state changes to the read state, and the analysis processing protocol data is started. At this time, the protocol data state changes to the processing state.
在步骤 S414中, 接收端写回应数据, 此时 socket状态边为正在写。  In step S414, the receiving end writes the response data, and the socket status side is writing.
作为本发明的又一实施例,接收端写回应数据包括两种情况, 即正常协议 交互以及文件传输, 在本发明实施例中, 协议交互包括请求、 处理以及回应, 这三个步骤即可表示该协议交互过程结束,而文件传输的过程是一个循环的过 程, 文件传输是通过分块来完成的,每一块文件的传输都是一个完整的协议交 互的过程。 下述给出详细的描述:  As another embodiment of the present invention, the receiving end write response data includes two cases, that is, normal protocol interaction and file transmission. In the embodiment of the present invention, the protocol interaction includes request, processing, and response, and the three steps can be represented. The protocol interaction process ends, and the file transfer process is a cyclic process. File transfer is done by blocking. The transfer of each file is a complete protocol interaction process. A detailed description is given below:
在步骤 S501中, 判断写回应包是否成功, 是则执行步骤 S502, 否则执行 步骤 S503。  In step S501, it is determined whether the write response packet is successful, if yes, step S502 is performed, otherwise step S503 is performed.
在步骤 S502中,回应包写成功,此时协议数据状态为写状态,关闭 socket。 处理完毕之后, socket状态为关闭, 而协议数据状态也为关闭状态, 协议 交互过程结束,如果是文件传输, 则只能在所有的分块的文件传输完成之后才 能关闭该 socket。  In step S502, the response packet is successfully written, and the protocol data state is in the write state, and the socket is closed. After processing, the socket status is off, and the protocol data status is also off. The protocol interaction process ends. If it is a file transfer, the socket can only be closed after all the block file transfers are completed.
在步骤 S503中, 如果回应包写失败, socket状态变化为 socket错误, 协 议数据状态变化为 socket写等待, 此时, 将 socket加入到工作队列。  In step S503, if the response to the packet write fails, the socket state changes to a socket error, and the protocol data state changes to a socket write wait. At this time, the socket is added to the work queue.
在步骤 S504中, 新线程不断查询该 socket的状态。 在步骤 S505中, 判断 socket是否可写, 是则执行步骤 S506, 否则执行步 骤 S507。 In step S504, the new thread continuously queries the state of the socket. In step S505, it is determined whether the socket is writable, if yes, step S506 is performed, otherwise step S507 is performed.
在步骤 S506中 , 通知 socket写回应包, 同时返回执行步骤 S501。  In step S506, the socket is notified to write the response packet, and the process returns to step S501.
在步骤 S507中, 继续查询, 直到 socket可写。  In step S507, the query continues until the socket is writable.
如果上述的网络连接是正常的协议交互, 则写一次回应包。  If the above network connection is a normal protocol interaction, then the response packet is written once.
如果上述连接是文件的传输, 则接收端多次向数据发送端写回应包,每发 送一次文件的分块都要进行写回应,其中对网络的流量是否超过设定值的检测 的详细流程如下所述:  If the above connection is a file transmission, the receiving end writes a response packet to the data sending end multiple times, and each time the file is sent, the file is written in response, wherein the detailed flow of detecting whether the network traffic exceeds the set value is as follows: Said:
在步骤 S601中, 判断文件数据的网络的流量是否超过设定值, 是则执行 步骤 S602, 否则结束。  In step S601, it is judged whether the flow rate of the network of the file data exceeds the set value, if yes, step S602 is performed, otherwise, it ends.
在步骤 S602中, 在读文件过程中返回读中断, 此时协议数据状态变化为 写数据用户等待, socket状态暂时变为空闲等待状态。  In step S602, a read interrupt is returned during the process of reading the file. At this time, the protocol data state changes to the write data user waits, and the socket state temporarily becomes the idle wait state.
在步骤 S603中, 将 socket加入到工作队列中。  In step S603, the socket is added to the work queue.
在步骤 S604中, 新线程不断查询上述工作队列中的 socket的状态, 即判 断上述 socket是否可写, 是则执行步骤 S605 , 否则执行继续查询。  In step S604, the new thread continuously queries the status of the socket in the work queue, that is, determines whether the socket is writable, and if yes, step S605 is performed, otherwise the query is continued.
在步骤 S605中, 通知 socket写文件数据。  In step S605, the socket is notified to write the file data.
在步骤 S606中, 在 socket不断写文件数据的过程中, 判断写数据是否成 功, 是则继续读取, 否则执行步骤 S607。  In step S606, in the process of continuously writing the file data by the socket, it is judged whether the write data is successful, and if yes, the reading is continued, otherwise step S607 is performed.
在步骤 S607中, socket状态变为错误状态, 协议数据状态变化为 socket 写等待, 将该 socket加入到工作队列。  In step S607, the socket state becomes an error state, and the protocol data state changes to a socket write wait, and the socket is added to the work queue.
在步骤 S608中,另外一个新线程不断查询该 socket的状态,即判断 socket 是否可写, 是则执行步骤 S609, 否则继续查询。  In step S608, another new thread continuously queries the status of the socket, that is, whether the socket is writable, and if yes, step S609 is performed, otherwise the query is continued.
在步骤 S609中, 通知该 socket写数据, 如此反复直到文件读完为止。 图 7示出了本发明实施例提供的数据传输系统的结构图,为了便于说明仅 示出与本发明实施例相关的部分, 其中, 数据发送系统 1 与数据接收系统 2 置于终端的软件单元、 硬件单元或者软硬件单元。  In step S609, the socket is notified to write data, and so on until the file is read. FIG. 7 is a structural diagram of a data transmission system according to an embodiment of the present invention. For convenience of description, only parts related to the embodiment of the present invention are shown, wherein the data transmission system 1 and the data receiving system 2 are placed in a software unit of the terminal. , hardware unit or hardware and software unit.
数据发送系统 1包括套接字建立模块 11、 连接请求发送模块 12、 通知插 槽注册模块 13以及套接字写数据判断处理模块 14, 其中:  The data transmission system 1 includes a socket establishment module 11, a connection request transmission module 12, a notification slot registration module 13, and a socket write data judgment processing module 14, wherein:
套接字建立模块 11建立套接字;连接请求发送模块 12发送网络连接请求; 当判断该连接成功时, 通知插槽注册模块 13注册该套接字的通知插槽; 套接 字写数据判断处理模块 14判断通过该套接字写数据是否成功, 当写数据成功 时, 则读取数据接收端的回应包; 当写数据不成功时, 将该套接字加入工作队 列,并不断检测该套接字的状态, 当该套接字可写时,通知该套接字可写数据。 The socket establishing module 11 establishes a socket; the connection request sending module 12 sends a network connection request; When it is determined that the connection is successful, the slot registration module 13 is notified to register the notification slot of the socket; the socket write data judgment processing module 14 determines whether the data is successfully written by the socket, and when the data is successfully written, Reading the response packet of the data receiving end; when the writing data is unsuccessful, the socket is added to the working queue, and the state of the socket is continuously detected, and when the socket is writable, the socket is notified to be writable data.
作为本发明的一个实施例, 套接字写数据处理判断模块 14还包括读取回 应包判断模块 141、 读取回应包处理模块 142 以及读取回应包判断处理模块 143, 其中:  As an embodiment of the present invention, the socket write data processing judging module 14 further includes a read response packet judging module 141, a read response packet processing module 142, and a read response packet judging processing module 143, wherein:
读取回应包判断模块 141判断读取接收端的回应包是否成功;当读取接收 端的回应包成功时,读取回应包处理模块 142则处理回应包; 当读取接收端的 回应包不成功时, 读取回应包判断处理模块 143将该套接字加入到工作队列 , 并不断检测套接字的状态, 当套接字可读时, 读取数据接收端的回应包。  The read response packet judgment module 141 determines whether the response packet of the read receiving end is successful; when the read response packet of the receiving end succeeds, the read response packet processing module 142 processes the response packet; when the response packet of the receiving end is unsuccessful, The read response packet judgment processing module 143 adds the socket to the work queue, and continuously detects the state of the socket. When the socket is readable, the response packet of the data receiving end is read.
在本发明实施例中, 套接字写数据判断处理模块 14还包括读网络流量判 断模块 144以及读流量处理模块 145, 读网络流量判断模块 144判断文件数据 的网络传输流量是否超过了预先设定值;当该文件数据的网络传输流量超过了 预先设定值时,读流量处理模块 145返回写中断,将 socket加入到工作队列中, 并判断查询 socket的状态, 当 socket可读时 , 通知 socket读取文件数据。  In the embodiment of the present invention, the socket write data judgment processing module 14 further includes a read network traffic judgment module 144 and a read traffic processing module 145. The read network traffic judgment module 144 determines whether the network transmission traffic of the file data exceeds a preset. Value; when the network transmission traffic of the file data exceeds a preset value, the read traffic processing module 145 returns a write interrupt, adds the socket to the work queue, and determines the state of the query socket. When the socket is readable, the socket is notified. Read file data.
数据接收系统 2包括监听套接字建立判断模块 21、连接请求判断模块 22、 新套接字选择模块 23以及套接字读取数据判断处理模块 24, 其中:  The data receiving system 2 includes a listening socket establishment determining module 21, a connection request judging module 22, a new socket selecting module 23, and a socket reading data judging processing module 24, wherein:
监听套接字建立判断模块 21建立一监听 socket, 并判断该 socket监听是 否成功; 连接请求判断模块 22判断监听 socket是否监听到网络连接请求; 当 连接成功时 ,新套接字选择模块 23监听的 socket会重新 accept—个新的 socket; 套接字读取数据判断处理模块 24判断通过新套接字读取数据是否成功, 当读 取数据成功时, 则读取数据发送端的请求包; 当读取数据不成功时, 将新套接 字加入工作队列, 并不断检测新套接字的状态, 当新套接字可读时, 通知新套 接字可读数据。  The listening socket establishment determining module 21 establishes a listening socket and determines whether the socket monitoring is successful; the connection request determining module 22 determines whether the listening socket listens to the network connection request; when the connection is successful, the new socket selecting module 23 monitors The socket will re-accept - a new socket; the socket read data judgment processing module 24 determines whether the data is successfully read by the new socket, and when the data is successfully read, the request packet of the data sender is read; When the data is unsuccessful, the new socket is added to the work queue, and the state of the new socket is continuously detected. When the new socket is readable, the new socket readable data is notified.
作为本发明的又一实施例, 套接字读取数据判断处理模块 24包括写回应 包判断模块 241、 写回应包处理模块 242以及写回应包判断处理模块 243, 其 中:  As still another embodiment of the present invention, the socket read data judgment processing module 24 includes a write response packet judgment module 241, a write response packet processing module 242, and a write response packet judgment processing module 243, wherein:
写回应包判断模块 241判断写回应包是否成功; 当写回应包成功时,写回 应包处理模块 242关闭该 socket; 写回应包判断处理模块 243当写回应包不成 功时, 将该新套接字加入到工作队列, 并不断检测该新套接字的状态, 当该新 套接字可写时, 写回应包。 The write response packet judgment module 241 determines whether the write response packet is successful; when the write response packet succeeds, the write back The packet processing module 242 closes the socket; the write response packet judgment processing module 243 adds the new socket to the work queue when the write response packet is unsuccessful, and continuously detects the state of the new socket, when the new set When the word is writable, write the response packet.
在本发明实施例中, 套接字读取数据判断处理模块 24还包括写网络流量 判断模块 244以及写流量处理模块 245 , 其中:  In the embodiment of the present invention, the socket read data judging processing module 24 further includes a write network traffic judging module 244 and a write traffic processing module 245, where:
写网络流量判断模块 244 判断文件数据的网络传输流量是否超过了预先 设定值; 当文件数据的网络传输流量超过了预先设定的值时, 写流量处理模块 返回读中断, 将 socket加入到工作队列中, 并判断 socket的状态, 当 socket 可写时, 通知 socket发送文件数据。  The write network traffic judgment module 244 determines whether the network transmission traffic of the file data exceeds a preset value; when the network transmission traffic of the file data exceeds a preset value, the write traffic processing module returns a read interrupt, and adds the socket to the work. In the queue, and determine the state of the socket, when the socket is writable, the socket is notified to send the file data.
本发明实施例通过一般的查询机制,对套接字建立状态机,套接字根据状 态机进行数据流转, 以及对套接字建立一个通知机制, 实现及时准确地通知套 接字数据流转的状态,这样在网络并发量很大的情况下,有效地处理了网络协 议以及网络连接。  The embodiment of the present invention establishes a state machine for a socket through a general query mechanism, and the socket performs data flow according to the state machine, and establishes a notification mechanism for the socket, so as to timely and accurately notify the state of the socket data flow. In this way, network protocols and network connections are effectively handled in the case of a large amount of network concurrency.
以上所述仅为本发明的较佳实施例而已, 并不用以限制本发明, 凡在本发 明的精神和原则之内所作的任何修改、等同替换和改进等, 均应包含在本发明 的保护范围之内。  The above is only the preferred embodiment of the present invention, and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection of the present invention. Within the scope.

Claims

权 利 要 求 Rights request
1、 一种数据的发送方法, 其特征在于, 所述方法包括下述步骤: 向数据接收端发送网络连接请求;  A method for transmitting data, characterized in that the method comprises the steps of: transmitting a network connection request to a data receiving end;
当连接成功并为预先建立的套接字注册通知插槽后 ,判断通过所述套接字 向数据接收端写数据是否成功, 当写数据成功时,读取所述数据接收端的回应 包; 当写数据不成功时, 将所述套接字加入工作队列, 当查询到所述套接字可 写时, 通知所述套接字向所述数据接收端写数据。  After the connection is successful and the notification slot is registered for the pre-established socket, it is judged whether the data is successfully written to the data receiving end by the socket, and when the data is successfully written, the response packet of the data receiving end is read; When the write data is unsuccessful, the socket is added to the work queue, and when the socket is queried, the socket is notified to write data to the data receiving end.
2、 如权利要求 1所述的数据的发送方法, 其特征在于, 所述读取数据接 收端的回应包进一步包括下述步骤:  2. The method of transmitting data according to claim 1, wherein the reading the response packet of the data receiving end further comprises the following steps:
判断读取数据接收端的回应包是否成功;  Determining whether the response packet of the read data receiving end is successful;
当读取所述数据接收端的回应包成功时 , 处理所述回应包;  Processing the response packet when reading the response packet of the data receiving end is successful;
当读取所述数据接收端的回应包不成功时, 将所述套接字加入工作队列, 当查询到所述套接字可读时, 读取所述数据接收端的回应包。  When the response packet of the data receiving end is unsuccessful, the socket is added to the working queue, and when the socket is readable, the response packet of the data receiving end is read.
3、 如权利要求 1或 2所述的数据的发送方法, 其特征在于, 当所述网络 连接请求为文件传输请求时, 所述回应包具体为文件数据, 所述读取数据接收 端的回应包还包括下述步骤:  The method for transmitting data according to claim 1 or 2, wherein, when the network connection request is a file transfer request, the response packet is specifically file data, and the response packet of the data receiving end is read. It also includes the following steps:
判断文件数据的网络传输流量是否超过预先设定值;  Determining whether the network transmission traffic of the file data exceeds a preset value;
当所述文件数据的网络传输流量超过预先设定值时,返回写中断, 并将所 述套接字加入到工作队列中;  When the network transmission traffic of the file data exceeds a preset value, returning a write interrupt, and adding the socket to the work queue;
判断所述套接字的状态, 当所述套接字可读时,通知所述套接字读所述文 件数据。  Determining the status of the socket, and notifying the socket to read the file data when the socket is readable.
4、 一种数据的接收方法, 其特征在于, 所述方法包括下述步骤: 当通过预先建立的监听套接字监听到数据发送端的连接请求时,所述监听 套接字重新选择一个新套接字;  A method for receiving data, characterized in that the method comprises the following steps: when the connection request of the data transmitting end is monitored through a pre-established listening socket, the listening socket reselects a new set. Socket
判断通过所述新套接字读数据是否成功,当读数据成功时,处理所述数据, 并向所述数据发送端写回应包; 当读取数据不成功时,将所述新套接字加入工 作队列, 并不断检测所述新套接字的状态, 当查询到所述新套接字可读时, 通 知所述新套接字读数据。  Determining whether the data is successfully read by the new socket, processing the data when the data is successful, and writing a response packet to the data sending end; when the reading data is unsuccessful, the new socket is Joining the work queue, and continuously detecting the status of the new socket, and notifying the new socket to read data when the new socket is readable.
5、 如权利要求 4所述的数据的接收方法, 其特征在于, 所述向数据发送 端写回应包进一步包括下述步骤: The data receiving method according to claim 4, wherein the transmitting to the data The write-response package further includes the following steps:
判断向数据发送端写回应包是否成功;  Determining whether the response packet is successfully written to the data sender;
当向数据发送端写回应包成功时, 关闭所述新套接字;  When the response packet is successfully written to the data transmitting end, the new socket is closed;
当向所述数据发送端写回应包不成功时, 将所述新套接字加入工作队列, 当查询到所述新套接字可写时, 向所述数据发送端写回应包。  When the response packet is unsuccessful to the data sending end, the new socket is added to the working queue, and when the new socket is queried, the response packet is written to the data sending end.
6、 如权利要求 4或 5所述的数据的接收方法, 其特征在于, 当所述网络 连接为文件传输时, 所述回应包具体为文件数据, 所述向数据接收端写回应包 还包括下述步骤:  The method for receiving data according to claim 4 or 5, wherein, when the network connection is file transmission, the response packet is specifically file data, and the writing of the response packet to the data receiving end further includes The following steps:
判断文件数据的网络传输流量是否超过预先设定值;  Determining whether the network transmission traffic of the file data exceeds a preset value;
当所述文件数据的网络传输流量超过预先设定值时,返回读中断, 并将所 述新套接字加入到工作队列中;  Returning a read interrupt when the network transmission traffic of the file data exceeds a preset value, and adding the new socket to the work queue;
判断所述新套接字的状态, 当所述新套接字可读时,通知所述新套接字读 所述文件数据。  Determining the status of the new socket, and notifying the new socket to read the file data when the new socket is readable.
7、 一种数据发送系统, 其特征在于, 所述系统包括:  7. A data transmission system, wherein the system comprises:
套接字建立模块, 用于建立套接字;  a socket building module for establishing a socket;
连接请求发送模块, 用于向数据接收端发送网络连接请求;  a connection request sending module, configured to send a network connection request to the data receiving end;
通知插槽注册模块, 用于当连接成功时, 注册所述套接字的通知插槽; 以 及  Notifying a slot registration module, for registering a notification slot of the socket when the connection is successful; and
套接字写数据判断处理模块,用于在所述通知插槽注册模块注册所述套接 字的通知插槽后, 判断通过所述套接字向数据接收端写数据是否成功, 当写数 据成功时, 读取所述数据接收端的回应包; 当写数据不成功时, 将所述套接字 加入工作队列, 当查询到所述套接字可写时,通知所述套接字向所述数据接收 端写数据。  a socket write data judging processing module, configured to determine, after the notification slot registration module registers the notification slot of the socket, whether the data is successfully written to the data receiving end by the socket, when writing data If successful, the response packet of the data receiving end is read; when the writing data is unsuccessful, the socket is added to the working queue, and when the socket is readable, the socket is notified to the The data receiving end writes data.
8、 如权利要求 7所述的数据发送系统, 其特征在于, 所述套接字写数据 判断处理模块还包括:  The data transmission system according to claim 7, wherein the socket write data judgment processing module further comprises:
读取回应包判断模块, 用于判断读取数据接收端的回应包是否成功; 读取回应包处理模块,用于当读取所述数据接收端的回应包成功时,处理 所述回应包; 以及  a read response packet determining module, configured to determine whether the response packet of the read data receiving end is successful; and a read response packet processing module, configured to process the response packet when the response packet of the data receiving end is successful;
读取回应包判断处理模块, 用于当读取所述数据接收端的回应包不成功 时, 将所述套接字加入工作队列, 当查询到所述套接字可读时, 读取所述数据 接收端的回应包。 The read response packet judgment processing module is configured to: when the response packet of the data receiving end is read, the response packet is unsuccessful The socket is added to the work queue, and when the socket is readable, the response packet of the data receiving end is read.
9、 如权利要求 7或 8所述的数据发送系统, 其特征在于, 套接字写数据 判断处理模块还包括:  The data transmission system according to claim 7 or 8, wherein the socket write data judgment processing module further comprises:
读网络传输流量判断模块, 用于当所述回应包具体为文件数据时, 判断所 述文件数据的网络传输流量是否超过预先设定值;  The network transmission traffic judging module is configured to: when the response packet is specifically file data, determine whether the network transmission traffic of the file data exceeds a preset value;
读流量处理模块, 用于当所述文件数据的网络传输流量超过预先设定值 时, 返回写中断, 并将所述套接字加入到工作队列中, 并判断所述套接字的状 态, 当所述套接字可读时, 通知套接字读所述文件数据。  The read traffic processing module is configured to: when the network transmission traffic of the file data exceeds a preset value, return a write interrupt, add the socket to the work queue, and determine the state of the socket, When the socket is readable, the socket is notified to read the file data.
10、 一种数据接收系统, 其特征在于, 所述系统包括:  10. A data receiving system, the system comprising:
监听套接字建立判断模块, 用于建立监听套接字, 并判断所述套接字监听 是否成功;  a monitoring socket establishment determining module, configured to establish a listening socket, and determine whether the socket monitoring is successful;
连接请求判断模块, 用于当所述监听套接字监听成功后, 判断所述监听套 接字是否监听到数据接收端的连接请求;  a connection request judging module, configured to determine, after the monitoring socket is successfully monitored, whether the listening socket listens to a connection request of the data receiving end;
新套接字选择模块,用于当所述连接请求判断模块监听到数据发送端的连 接请求时, 所述监听套接字重新选择一个新套接字; 以及  a new socket selection module, configured to: when the connection request judging module listens to the connection request of the data sending end, the listening socket reselects a new socket;
套接字读取数据判断处理模块,用于判断通过所述新套接字读数据是否成 功, 当读数据成功时, 处理所述数据, 并向所述数据发送端写回应包; 当读取 数据不成功时,将所述新套接字加入工作队列, 并不断检测所述新套接字的状 态, 当查询到所述新套接字可读时, 通知所述新套接字读数据。  a socket read data judging processing module, configured to judge whether the data is successfully read by the new socket, when the read data is successful, process the data, and write a response packet to the data sending end; When the data is unsuccessful, the new socket is added to the work queue, and the state of the new socket is continuously detected. When the new socket is queried, the new socket read data is notified. .
11、 如权利要求 10所述的数据接收系统, 其特征在于, 所述套接字读取 数据判断处理模块还包括:  The data receiving system according to claim 10, wherein the socket read data judgment processing module further comprises:
写回应包判断模块, 用于判断向数据发送端写回应包是否成功; 写回应包处理模块,用于当向所述数据发送端写回应包成功时, 关闭所述 新套接字;  a response packet judgment module, configured to determine whether the response packet is successfully written to the data sending end; and a write response packet processing module, configured to close the new socket when the response packet is successfully written to the data sending end;
写回应包判断处理模块,用于当向所述数据发送端写回应包不成功时,将 所述新套接字加入工作队列, 当查询到所述新套接字可写时, 向所述数据发送 端写回应包。  a write response packet judgment processing module, configured to add the new socket to the work queue when the write response packet to the data sender is unsuccessful, and when the query is that the new socket is writable, The data sender writes a response packet.
12、如权利要求 10或 11所述的数据接收系统, 其特征在于, 所述套接字 读取数据判断处理模块还包括: The data receiving system according to claim 10 or 11, wherein said socket The read data judgment processing module further includes:
写网络传输流量判断模块, 用于当所述回应包具体为文件数据时, 判断文 件数据的网络传输流量是否超过预先设定值;  Writing a network transmission traffic judging module, configured to determine whether the network transmission traffic of the file data exceeds a preset value when the response packet is specifically file data;
写流量处理模块, 用于当所述文件数据的网络传输流量超过预先设定值 时, 返回读中断, 并将所述新套接字加入到工作队列中, 并判断所述新套接字 的状态, 当所述新套接字可读时, 通知所述新套接字读所述文件数据。  a write traffic processing module, configured to: when the network transmission traffic of the file data exceeds a preset value, return a read interrupt, add the new socket to the work queue, and determine the new socket a state, when the new socket is readable, notifying the new socket to read the file data.
PCT/CN2008/071577 2007-09-07 2008-07-08 A method and system for transmitting data WO2009030130A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN 200710076929 CN101202704B (en) 2007-09-07 2007-09-07 Method and system for transmitting data
CN200710076929.2 2007-09-07

Publications (1)

Publication Number Publication Date
WO2009030130A1 true WO2009030130A1 (en) 2009-03-12

Family

ID=39517677

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2008/071577 WO2009030130A1 (en) 2007-09-07 2008-07-08 A method and system for transmitting data

Country Status (2)

Country Link
CN (1) CN101202704B (en)
WO (1) WO2009030130A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111311471A (en) * 2019-01-25 2020-06-19 上海雪湖信息科技有限公司 Batch picture segmentation, scheduling, processing and synthesizing system and method based on FPGA (field programmable Gate array) calculation
CN111683138A (en) * 2020-06-05 2020-09-18 中国有色金属长沙勘察设计研究院有限公司 Socket-based efficient custom data transmission method
CN114363428A (en) * 2022-01-06 2022-04-15 齐鲁空天信息研究院 Socket-based data transmission method
CN114860483A (en) * 2022-06-17 2022-08-05 中国人民解放军陆军炮兵防空兵学院 Method and system for rapidly acquiring equipment data and efficiently persisting

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101202704B (en) * 2007-09-07 2010-08-18 深圳市同洲电子股份有限公司 Method and system for transmitting data
CN102546733B (en) * 2010-12-31 2015-09-02 海信集团有限公司 Data communications method and device
CN103067788A (en) * 2012-12-17 2013-04-24 四川长虹电器股份有限公司 Electric appliance control method based on intelligent television
CN103384265B (en) * 2013-05-23 2016-04-06 上海斐讯数据通信技术有限公司 The application layer implementation method of GVRP agreement and system
CN103338156B (en) * 2013-06-17 2016-08-24 南京国电南自美卓控制系统有限公司 A kind of name pipeline server concurrent communication method based on thread pool
CN103501245B (en) * 2013-09-26 2017-02-08 北京搜狐互联网信息服务有限公司 Network-event processing method and device
CN105940658B (en) * 2015-01-04 2019-04-26 华为技术有限公司 A kind of transmission method of user data, device and terminal
CN107360059B (en) * 2017-07-28 2019-03-01 Oppo广东移动通信有限公司 Network detecting method, network detection device and intelligent terminal
CN108833469A (en) * 2018-04-27 2018-11-16 厦门理工学院 The resource transmission method, device and terminal device of a kind of terminal to terminal
CN110198312B (en) * 2019-05-23 2021-12-24 北京华三通信技术有限公司 Message processing method and device
CN110213177B (en) * 2019-06-06 2022-12-20 上海华测导航技术股份有限公司 Time-sharing sending method based on 4g module

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20040074435A (en) * 2003-02-18 2004-08-25 삼성전자주식회사 method of data transmission between processor using socket communication
CN1588902A (en) * 2004-09-30 2005-03-02 西安西电捷通无线网络通信有限公司 Method for moving node passing through NAT registration
CN1717071A (en) * 2004-06-28 2006-01-04 华为技术有限公司 Method for transmitting SABP news by ICP
CN101202704A (en) * 2007-09-07 2008-06-18 深圳市同洲电子股份有限公司 Method and system for transmitting data

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100560752B1 (en) * 2004-07-21 2006-03-13 삼성전자주식회사 System for managing socket connection and method for checking of socket connection state

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20040074435A (en) * 2003-02-18 2004-08-25 삼성전자주식회사 method of data transmission between processor using socket communication
CN1717071A (en) * 2004-06-28 2006-01-04 华为技术有限公司 Method for transmitting SABP news by ICP
CN1588902A (en) * 2004-09-30 2005-03-02 西安西电捷通无线网络通信有限公司 Method for moving node passing through NAT registration
CN101202704A (en) * 2007-09-07 2008-06-18 深圳市同洲电子股份有限公司 Method and system for transmitting data

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111311471A (en) * 2019-01-25 2020-06-19 上海雪湖信息科技有限公司 Batch picture segmentation, scheduling, processing and synthesizing system and method based on FPGA (field programmable Gate array) calculation
CN111311471B (en) * 2019-01-25 2023-04-28 上海雪湖信息科技有限公司 Batch picture segmentation scheduling processing synthesis system and method based on FPGA (field programmable Gate array) calculation
CN111683138A (en) * 2020-06-05 2020-09-18 中国有色金属长沙勘察设计研究院有限公司 Socket-based efficient custom data transmission method
CN111683138B (en) * 2020-06-05 2023-06-16 中国有色金属长沙勘察设计研究院有限公司 Socket-based efficient custom data transmission method
CN114363428A (en) * 2022-01-06 2022-04-15 齐鲁空天信息研究院 Socket-based data transmission method
CN114363428B (en) * 2022-01-06 2023-10-17 齐鲁空天信息研究院 Socket-based data transmission method
CN114860483A (en) * 2022-06-17 2022-08-05 中国人民解放军陆军炮兵防空兵学院 Method and system for rapidly acquiring equipment data and efficiently persisting

Also Published As

Publication number Publication date
CN101202704B (en) 2010-08-18
CN101202704A (en) 2008-06-18

Similar Documents

Publication Publication Date Title
WO2009030130A1 (en) A method and system for transmitting data
WO2021121370A1 (en) Message loss detection method and apparatus for message queue
WO2023284699A1 (en) Protocol stack data transmission method based on linux system, and computer device and storage medium
US9537786B2 (en) Method, device, and system for information processing based on distributed buses
EP1841162B1 (en) Method and system for an os virtualization-aware network interface card
US7171464B1 (en) Method of tracing data traffic on a network
WO2022032984A1 (en) Mqtt protocol simulation method and simulation device
WO2020006902A1 (en) Batch payment method and apparatus, computer device, and storage medium
WO2018214911A1 (en) Data transmission method and apparatus, and electronic device
WO2012149746A1 (en) Serial port baud rate configuration method, relevant equipment, and system
WO2012155440A1 (en) Method and apparatus for processing service request based on hyper text transfer protocol
TW201033813A (en) Network adaptor optimization and interrupt reduction
CN107454177A (en) The dynamic realizing method of network service
CN116150054A (en) Interrupt information processing method based on PCIE
CN111131499A (en) Concurrent and asynchronous task processing method and device thereof
WO2020006896A1 (en) Balance monitoring method, apparatus, computer device, and storage medium
WO2020006901A1 (en) Fund collection method and apparatus, computer device, and storage medium
CN116431558B (en) AXI protocol-based request response method, device, system and medium
WO2010069214A1 (en) Method and equipment for field filtering
CN111064729A (en) Message processing method and device, storage medium and electronic device
EP1575236A1 (en) Connectivity confirmation method for network storage device and host computer
WO2022267348A1 (en) Bmc parameter configuration and effect-taking method and apparatus, device, and medium
WO2023115678A1 (en) Data communication methods and apparatuses, electronic device and storage medium
CN113992740A (en) Middleware based on autonomous control and data transmission method
CN110061886B (en) Prepress network management system based on SNMP

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 08773131

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 08773131

Country of ref document: EP

Kind code of ref document: A1

REG Reference to national code

Ref country code: BR

Ref legal event code: B01E

Ref document number: PI0817465

Country of ref document: BR

Free format text: SOLICITA-SE A REGULARIZACAO DA PROCURACAO, UMA VEZ QUE A PROCURACAO APRESENTADA NAO POSSUI LOCAL E DATA.

ENPW Started to enter national phase and was withdrawn or failed for other reasons

Ref country code: BR

Ref document number: BR