I am using V3.4sp1 on a windows CE PLC. I use TPC/IP sockets for communication, and listen for a connection like this
CASETCPStateOF0: //CreateaSocketSocketCreateHandle :=SysSockCreate(SOCKET_AF_INET, SOCKET_STREAM, 0, ADR(SocketError)); IFSocketCreateHandle<>SysTypes.RTS_INVALID_HANDLETHENdwValue :=1;//Settheoptionthatwecanreuse'old'portaddressesSocketError :=SysSockSetOption(SocketCreateHandle,
SOCKET_SOL, SOCKET_SO_REUSEADDR, ADR(dwValue), SIZEOF(dwValue));TCPState :=10;END_IF10: //BindthesockettoourIPaddressandportSocketAddress.sin_family :=SOCKET_AF_INET;SocketError :=SysSockInetAddr(InetAddr, ADR(SocketAddress.sin_addr));SocketAddress.sin_port :=SysSockHtons(TCP_LEUTWIL);bResult :=SysSockBind(SocketCreateHandle, ADR(SocketAddress), SIZEOF(SocketAddress));IFbResult<>SysTypes.RTS_INVALID_HANDLETHENTCPState :=20;END_IF20: //ListenforaconnectionbResult :=SysSockListen(SocketCreateHandle, diMaxConnections);IFbResult<>SysTypes.RTS_INVALID_HANDLETHENMasterSocketList.fd_count :=1; // only socket is the listeningMasterSocketList.fd_array[0] :=SocketCreateHandle;dwValue :=1;//SysSockIoctl(SocketCreateHandle, SOCKET_FIONBIO, ADR(dwValue)); // set to non blockingTCPState :=30;END_IF30: //Buildalistofopensocketsanduseselecttodetectactivity(read)FDCopy(); // Copy master list to slaveSelectTimeOut.tv_sec :=0;SelectTimeOut.tv_usec :=10; // very short time outbResult :=SysSockSelect(SOCKET_FD_SETSIZE, ADR(SlaveSocketList), 0, 0, ADR(SelectTimeOut), ADR(diSize));IFdiSize>0THEN//Positiveresultsocketshaveactivity(countofactivesockets)TCPState :=40;TCPindex :=0;END_IF
But after a warm start very often I can no longer connect to the PLC with TCP. The application is still running in state 30 above but socket will not accept a connection. Anybody got any ideas or is it a problem with the library ?
Regards
Dave W
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DaveW hat geschrieben:
Hi
I am using V3.4sp1 on a windows CE PLC. I use TPC/IP sockets for communication, and listen for a connection like this
CASE TCPState OF
0: // Create a Socket
SocketCreateHandle := SysSockCreate(SOCKET_AF_INET, SOCKET_STREAM, 0, ADR(SocketError));
IF SocketCreateHandle <> SysTypes.RTS_INVALID_HANDLE THEN
dwValue := 1;
// Set the option that we can reuse 'old' port addresses
SocketError := SysSockSetOption(SocketCreateHandle,
SOCKET_SOL, SOCKET_SO_REUSEADDR, ADR(dwValue), SIZEOF (dwValue));
TCPState := 10;
END_IF
10: // Bind the socket to our IP address and port
SocketAddress.sin_family := SOCKET_AF_INET ;
SocketError := SysSockInetAddr(InetAddr, ADR(SocketAddress.sin_addr));
SocketAddress.sin_port := SysSockHtons(TCP_LEUTWIL);
bResult := SysSockBind(SocketCreateHandle, ADR(SocketAddress), SIZEOF(SocketAddress));
IF bResult <> SysTypes.RTS_INVALID_HANDLE THEN
TCPState := 20;
END_IF
20: // Listen for a connection
bResult := SysSockListen(SocketCreateHandle, diMaxConnections);
IF bResult <> SysTypes.RTS_INVALID_HANDLE THEN
MasterSocketList.fd_count := 1; // only socket is the listening
MasterSocketList.fd_array[0] := SocketCreateHandle;
dwValue := 1;
//SysSockIoctl(SocketCreateHandle, SOCKET_FIONBIO, ADR(dwValue)); // set to non blocking
TCPState := 30;
END_IF
30: // Build a list of open sockets and use select to detect activity (read)
FDCopy(); // Copy master list to slave
SelectTimeOut.tv_sec := 0;
SelectTimeOut.tv_usec := 10; // very short time out
bResult := SysSockSelect(SOCKET_FD_SETSIZE, ADR(SlaveSocketList), 0, 0, ADR(SelectTimeOut), ADR(diSize));
IF diSize > 0 THEN // Positive result sockets have activity (count of active sockets)
TCPState := 40;
TCPindex := 0;
END_IF
But after a warm start very often I can no longer connect to the PLC with TCP. The application is still running in state 30 above but socket will not accept a connection. Anybody got any ideas or is it a problem with the library ?
Regards
Dave W
Hi, I'm working on a similar project. I have a raspberry in which I need to run a TCP server where I will receive messages from clients by sockets. I can not get it to work properly, have you managed to get it to work properly? Do you have more information about the server or an example project?
Thank you very much.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I am using V3.4sp1 on a windows CE PLC. I use TPC/IP sockets for communication, and listen for a connection like this
But after a warm start very often I can no longer connect to the PLC with TCP. The application is still running in state 30 above but socket will not accept a connection. Anybody got any ideas or is it a problem with the library ?
Regards
Dave W
Hi, I'm working on a similar project. I have a raspberry in which I need to run a TCP server where I will receive messages from clients by sockets. I can not get it to work properly, have you managed to get it to work properly? Do you have more information about the server or an example project?
Thank you very much.