title: I can't uncheck use server mode with command in facestation suprema device when device in server mode
body: <p>I have a service-based project and I want to put suprema device server mode On or OFF with command... I have Facestation device and develop this in my project...when the device is not in server mode I can write config on this with BS_WriteConfigUDP method of BSSDK and write successfully but when the device connects to server then I can't write config and give error -105 please help me...thanks</p>
  
  <pre><code>public bool SetUseServer(ViewDevice Device, bool SetServer)
      {
          int _deviceId = 0;
          int handle = 0;
          BSSDK.BS_OpenInternalUDP(ref handle);
          BSSDK.BS_SearchDeviceInLAN(handle, ref m_NumOfDevice, m_DeviceID, m_DeviceType, DeviceAddr);
          uint targetAddress = (uint)IPAddress.Parse(Device.DeviceIp).Address;
  
          if (m_DeviceAddr.Length &gt; 0 &amp;&amp; Array.Exists(m_DeviceAddr, x =&gt; x.Equals(targetAddress)))
          {
              Device.TcpPort = Device.TcpPort ?? 1470;
              setConfigData.useServer = SetServer ? (uint)2 : 0;
              setConfigData.serverPort = (uint)serverPort;
              setConfigData.port = (uint)serverPort;
              setConfigData.maxConnection = maxConnections;
              setConfigData.useDHCP = false;
              setConfigData.syncTimeWithServer = SetServer;
              setConfigData.reserved = new byte[48];
              setConfigData.lanType = 1;
              byte[] serverIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(x =&gt; x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.GetAddressBytes();
              string ipServer = Empty;
              if (serverIP != null)
              {
                  foreach (var b in serverIP)
                  {
                      ipServer = ipServer + b + ".";
                  }
                  ipServer = ipServer.Remove(ipServer.LastIndexOf('.'));
              }
  
              string defaultGateway = Empty;
              foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
              {
                  if (f.OperationalStatus == OperationalStatus.Up)
                  {
                      //UnicastIPAddressInformationCollection UnicastIPInfoCol = f.GetIPProperties().UnicastAddresses;
                      foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                      {
                          defaultGateway = d.Address.ToString();
                      }
                  }
              }
  
              byte[] addr = Encoding.ASCII.GetBytes(Device.DeviceIp);
              setConfigData.ipAddr = new byte[32];
              Buffer.BlockCopy(addr, 0, setConfigData.ipAddr, 0, addr.Length);
  
              addr = Encoding.ASCII.GetBytes(defaultGateway);
              setConfigData.gateway = new byte[32];
              Buffer.BlockCopy(addr, 0, setConfigData.gateway, 0, addr.Length);
  
              addr = Encoding.ASCII.GetBytes("255.255.255.0");
              setConfigData.subnetMask = new byte[32];
              Buffer.BlockCopy(addr, 0, setConfigData.subnetMask, 0, addr.Length);
  
              addr = Encoding.ASCII.GetBytes(ipServer);
              setConfigData.serverIP = new byte[32];
              Buffer.BlockCopy(addr, 0, setConfigData.serverIP, 0, addr.Length);
  
              IntPtr config = Marshal.AllocHGlobal(Marshal.SizeOf(setConfigData));
              Marshal.StructureToPtr(setConfigData, config, true);
  
              int index = Array.IndexOf(m_DeviceAddr, Array.Find(m_DeviceAddr, x =&gt; x.Equals(targetAddress)));
              _deviceId = m_DeviceID[index];
  
              if (BSSDK.BS_WriteConfigUDP(handle, targetAddress, _deviceId, BSSDK.BS_CONFIG_TCPIP, Marshal.SizeOf(setConfigData), config) == BSSDK.BS_SUCCESS)
              {
                  Marshal.FreeHGlobal(config);
                  if (SetServer &amp;&amp; resetEvent.WaitOne(28000))
                  {
                      return true;
                  }
                  else
                  {
                      setConfigData.useServer = 0;
                      BSSDK.BS_WriteConfigUDP(handle, targetAddress, _deviceId, BSSDK.BS_CONFIG_TCPIP, Marshal.SizeOf(setConfigData), config);
                  }
                  return true;
              }
          }
          return false;
      }
  </code></pre>