Trying to start a TcpListener using NModbus4 library but it won't start with certain IP Addresses. Below is my code:
case "TCP":
try
{
TcpListener slaveTcpListener = new TcpListener(IP, Port);
slaveTcpListener.Start(); // Error occurs here
slave = ModbusTcpSlave.CreateTcp(SlaveID, slaveTcpListener);
slave.DataStore = DataStoreFactory.CreateDefaultDataStore(MaxCoil, MaxDI, MaxHR, MaxIR);
slave.DataStore.DataStoreReadFrom += new EventHandler<DataStoreEventArgs>(dataStore_DataStoreReadFrom);
slave.ModbusSlaveRequestReceived += Slave_ModbusSlaveRequestReceived;
slave.Listen();
}
catch
{
// Exception Handle
}
The code works fine with IP such as 127.0.0.1
but it won't work with something like 50.50.50.50
.
It fails at:
slaveTcpListener.Start();
Even if I validate input IP Address (50.50.50.50
passed the IP validation), the code fails at that line and I don't know how to handle this problem.