Codesys3.5 TcpSocket相关

PROGRAM PLC_PRG
VAR
	bCreate		: BOOL;
	bSet		: BOOL;
	bBind		: BOOL;
	bListen		: BOOL;
	bClose		: BOOL;
	bAccept		: BOOL;
	bRecv		: BOOL;
	CreatResult : RTS_IEC_Result;
	bindResult	: RTS_IEC_Result;
	ListenResult: RTS_IEC_Result;
	AcceptResult: RTS_IEC_Result;
	RecvResult	: RTS_IEC_Result;
	
	TcpServer	: RTS_IEC_HANDLE;//监听套接字
	AcSocket	: RTS_IEC_HANDLE;//通信套接字
	
	ip			: INADDR;
	IPPort		: SOCKADDRESS;//服务端
	CIPPort		: SOCKADDRESS;
	
	dwValue		: DWORD;
	SizeCIPPort	: DINT;
	
	Recv		: ARRAY [0..199] OF BYTE;
	SizeRecv	: DINT;
END_VAR
ip.S_un_b.s_b1:=192;ip.S_un_b.s_b2:=168;ip.S_un_b.s_b3:=88;ip.S_un_b.s_b4:=100;

IPPort.sin_addr 	:=ip;				//监听IP
IPPort.sin_family	:=SOCKET_AF_INET;	//协议族,IPV4、IPV6
IPPort.sin_port 	:=SysSockHtons(504);//端口号

//创建TCP/IP 通信套接字
//协议族,socket类型
//指定协议,SOCKET_IPPROTO_TCP
IF bCreate THEN
	TcpServer:=SysSockCreate(SOCKET_AF_INET,SOCKET_STREAM,SOCKET_IPPROTO_TCP,ADR(CreatResult));
	

你可能感兴趣的:(Codesys3.5 TcpSocket相关)