A method for transmitting an optical signal, comprising: performing diffraction processing on an input optical signal obtained from an input port, to obtain signal light and crosstalk light, wherein the signal light is output to a target output port in a plurality of output ports; wherein the diffraction processing comprises: deflecting, in a second direction, a diffraction direction of a part or all of the crosstalk light, to output the part or all of the crosstalk light to an area outside all the output ports, wherein the second direction intersects with an input direction of the input port, and the method being characterized in that: the diffraction processing further comprises: determining, based on a first direction, a first deflection angle of a diffraction direction of the signal light in the first direction and a second deflection angle of the crosstalk light in the first direction, wherein the first direction is a connection direction from the input port to the target output port, and wherein the first deflection angle of a diffraction direction of the signal light in the first direction is an angle of deflection of the signal light in a plane determined by the input direction of the input port and the first direction, and the second deflection angle of the crosstalk light in the first direction is an angle of deflection of the crosstalk light in the plane determined by the input direction of the input port and the first direction, and the first deflection angle of the signal light in the first direction is used to enable a part of the signal light to be transmitted to an area outside the target output port. performing diffraction processing on an input optical signal obtained from an input port, to obtain signal light and crosstalk light, wherein the signal light is output to a target output port in a plurality of output ports; wherein the diffraction processing comprises: deflecting, in a second direction, a diffraction direction of a part or all of the crosstalk light, to output the part or all of the crosstalk light to an area outside all the output ports, wherein the second direction intersects with an input direction of the input port, and the method being characterized in that: the diffraction processing further comprises: determining, based on a first direction, a first deflection angle of a diffraction direction of the signal light in the first direction and a second deflection angle of the crosstalk light in the first direction, wherein the first direction is a connection direction from the input port to the target output port, and wherein the first deflection angle of a diffraction direction of the signal light in the first direction is an angle of deflection of the signal light in a plane determined by the input direction of the input port and the first direction, and the second deflection angle of the crosstalk light in the first direction is an angle of deflection of the crosstalk light in the plane determined by the input direction of the input port and the first direction, and the first deflection angle of the signal light in the first direction is used to enable a part of the signal light to be transmitted to an area outside the target output port. determining, based on a first direction, a first deflection angle of a diffraction direction of the signal light in the first direction and a second deflection angle of the crosstalk light in the first direction, wherein the first direction is a connection direction from the input port to the target output port, and wherein the first deflection angle of a diffraction direction of the signal light in the first direction is an angle of deflection of the signal light in a plane determined by the input direction of the input port and the first direction, and the second deflection angle of the crosstalk light in the first direction is an angle of deflection of the crosstalk light in the plane determined by the input direction of the input port and the first direction, and the first deflection angle of the signal light in the first direction is used to enable a part of the signal light to be transmitted to an area outside the target output port.