The embodiment of the invention discloses a network coding method for the streaming media of a peer-to-peer network. The method includes the following steps that: based on a
segment length constraint, nodes are classified, the
segment length constraint is a feasible maximum
segment length which can be adopted by each node, the nodes are divided into L levels, which respectively have k1 nodes, k2 nodes, ..., kL nodes, and n, which is node number, is equal to k1 plus k2 plus ... plus kL; according to the node levels L, the different segment lengths gi of the nodes of each level are determined, and i is equal to 1, 2, ..., L; according to the node levels L and the segment lengths gi of each level, the data in the segments are randomly network-coded, so that in-segment coding is implemented; the nodes with segment lengths in all the levels cooperate with one another, and the nodes of the high level receive the data requests of the nodes of the same level or the low level, and send data to the request nodes. According to the method provided by the embodiment, the buffers and other resources provided by different nodes are sufficiently utilized, the advantages of network coding are maintained, the
utilization rate of network bandwidth can be improved by increasing the effective load rate of coded data, and the method is highly practical.