A network coding method in a communication system in which data is transmitted between a first terminal device and a second terminal device through an electromagnetic hypersurface array antenna in which antenna units made of different metamaterials are combined, data sending, network coding, and receiving are completed in one transmission/reception slot of a transmission resource, and network coding is performed as a time domain superposition, comprising: determining, by a first terminal device , first indication information, wherein the first indication information indicates whether to preprocess a phase of first to-be-coded data to be sent by the first terminal device , by shifting the phase of an analog signal of the first to-be-coded data by a specific angle belonging to [ π - α , π + β ], where 0 ≤ α , β ≤ π / 4; and transmitting, by the first terminal device , data to the second terminal device in the transmission/reception slot through the electromagnetic hypersurface array antenna , wherein the transmitting comprises: sending, by the first terminal device , third to-be-coded data to the electromagnetic hypersurface array antenna in the transmission/reception slot, and receiving first network coded data from the electromagnetic hypersurface array antenna in the transmission/reception slot, wherein the third to-be-coded data is obtained based on the first indication information and the first to-be-coded data; and obtaining, by the first terminal device , second to-be-coded data from the second terminal device based on the third to-be-coded data and the first network coded data. determining, by a first terminal device , first indication information, wherein the first indication information indicates whether to preprocess a phase of first to-be-coded data to be sent by the first terminal device , by shifting the phase of an analog signal of the first to-be-coded data by a specific angle belonging to [ π - α , π + β ], where 0 ≤ α , β ≤ π / 4; and transmitting, by the first terminal device , data to the second terminal device in the transmission/reception slot through the electromagnetic hypersurface array antenna , wherein the transmitting comprises: sending, by the first terminal device , third to-be-coded data to the electromagnetic hypersurface array antenna in the transmission/reception slot, and receiving first network coded data from the electromagnetic hypersurface array antenna in the transmission/reception slot, wherein the third to-be-coded data is obtained based on the first indication information and the first to-be-coded data; and obtaining, by the first terminal device , second to-be-coded data from the second terminal device based on the third to-be-coded data and the first network coded data. sending, by the first terminal device , third to-be-coded data to the electromagnetic hypersurface array antenna in the transmission/reception slot, and receiving first network coded data from the electromagnetic hypersurface array antenna in the transmission/reception slot, wherein the third to-be-coded data is obtained based on the first indication information and the first to-be-coded data; and obtaining, by the first terminal device , second to-be-coded data from the second terminal device based on the third to-be-coded data and the first network coded data. <EOS>