private String GetUserByFingerprint(String fp) { String sError = null; try { DatagramSocket sockUdp = new DatagramSocket(); sockUdp.setSoTimeout(8000); InetAddress adrs_Idsvr = InetAddress.getByName("127.0.0.1");// seidsvr.jar UDP 17020 byte[] wbuf = String.format("SysID=wssvr;Finger=%s;", fp).getBytes(); // fp: 0301... DatagramPacket wPkt = new DatagramPacket(wbuf, wbuf.length, adrs_Idsvr, 17020); sockUdp.send(wPkt); Thread.sleep(1000); byte[] rbuf = new byte[256]; DatagramPacket rPacket = new DatagramPacket(rbuf, rbuf.length); sockUdp.receive(rPacket);// Blocking... sockUdp.close(); String sBuf = new String(rbuf); // DevMsg=90,{UserName}; int iEqual = sBuf.indexOf('='); int iComma = sBuf.indexOf(','); int iCol = sBuf.indexOf(';'); if (iEqual>0 && iComma>0 && iCol>0) { if (iComma+1 == iCol) // not match return null; else return String.format("{\"UserName\":\"%s\", \"MatchScore\":%s}", sBuf.substring(iComma+1, iCol), sBuf.substring(iEqual+1, iComma)); } else { sError = sBuf; } } catch (Exception e) { sError = "GetUserByFingerprint: "+e.getMessage(); log.error(sError); } return String.format("{\"ErrorMessage\":\"%s\"}", sError); }
时间: 2024-04-28 16:19:25 浏览: 137
j2me-net.rar_HTTP java_datagramsocket_j2me http_java socket _jav
这段代码看起来像是一个 Java 方法,它的作用是根据指纹获取用户信息。它使用了 UDP 协议向本地地址为 127.0.0.1、端口号为 17020 的服务器发送了一个字符串,其中包含了系统 ID 和指纹信息。然后该方法等待 1000 毫秒,接收从服务器返回的消息,并解析该消息以获取用户名和匹配得分。如果解析失败,则该方法将返回错误消息。
阅读全文