11

I want to connect bio metric machine using C#. I am using zkemkeeper dll for connecting with machine

I have used connect_net method to connect with ip address and port

public partial class Form1 : Form
{
    public zkemkeeper.CZKEM machineObj = new zkemkeeper.CZKEM();
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        bool status = false;        
        status = machineObj.Connect_Net("10.10.32.162", 5005);
        if (status)
        {
            MessageBox.Show("Connect to machine successfully");
        }
    }
}

Now this machineObj.Connect_Net always return false what is the reason behind this any one have solution?

error code is -2

Chitra Nandpal
  • 413
  • 4
  • 24
  • Does https://www.codeproject.com/Questions/1180738/Zkemkeeper-connect-net-failed help? – mjwills Jul 23 '18 at 05:54
  • i tried first two solution,1 solution is firewall problem but its work fine when i ping same ip address with my cmd,and second there is not white or black list ip config in device – Chitra Nandpal Jul 23 '18 at 05:59
  • Few things would help find answer: 1) sdk version & platform (x86/x64), 2) device name. Code -2 usually stands for IO error for these dlls (valid). App looks OK. Switch&Build your sln platform to x86 target platform if you got x86 dll. Older dlls may require older runtime (e.g. Visual C++ 2003). Ensure dll is properly installed via regsvr32 (C:\Windows\SysWow64 for x86 on x64 host, Sys32 folder otherwise). Ensure no dll version conflicts (if you tried few keep 1 - uninstall). Try default port 4370 (public and admin ports may exist). Lookup manuals for sdk/device ports, dll support. – d.stack Jul 26 '18 at 00:27
  • Judging from the sparse documentation, this api's GetLastError() function returns the OS error code, making it negative to indicate failure. Do update the snippet to show that you are actually using GetLastError(). That makes -2 a bit odd, you'd expect a socket error code when it has trouble connecting to the other machine. Error 2 means "File not found". With some luck, the SysInternals' Process Monitor utility can show you what file it is trying to find. – Hans Passant Jul 26 '18 at 11:18
  • @Chitra Nandpal, did u get error code -7 or -2, bcoz `Connect_Net` gives -7 in mostly so try to add inbound rule in firewall with your port like `4370` may it solves your problem – er-sho Aug 01 '18 at 05:26

1 Answers1

2

there was a long time ago when I dealt with it, I found some useful tips on code project in this post:

1) The connection is denied by firewall settings (on your system or a router): Check the firewall logs.

2) The device has a white or black list configuration that does not allow connections from your system's IP address: Check the configuration of the device and the log files (if such exist).

3) The packages are not routed when your system is not in the same subnet as the device: Configure port forwarding on the device's next gateway.

if your device as a white or blacklist configuration, you better start digging into your logs and device configuration.

Meanwhile start exploring your firewall as well, if there is any, to make sure you are not being blocked from connecting to the device.

edit: I saw your comment so this might be the cause of your issue.

the most common reason however, is the third because it is easier to miss, it is unnoticeable and does not catch the eye. Make sure your system is in the same subnet as the device. If not, configure your port forwarding on the device.

Barr J
  • 10,636
  • 1
  • 28
  • 46