Answer Question
Detecting the device over LAN using .NET 2.0 in c# 2.0
Hi to all,
I am wondering how to detect the device (say attendance modular) on LAN. The device is connected with LAN.
I want to read the data from the device once someone swap their card.( likes people do when they enter into the office premise).
I have Java Code with me. But I don't know how to do it in .NET.
Any suggestion please.
// Sample code
/*
* Server.java
*
* Created on August 4, 2005, 2:53 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package allsec;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
/**
*/
public class Server {
/** Creates a new instance of Server */
public Server() {
}
public static void main(String[] args) {
Socket incoming = new Socket();
String data=new String();
try {
//create server socket
ServerSocket server = new ServerSocket(9999);
incoming = server.accept();
System.out.println("Connection Opened");
BufferedReader in = new BufferedReader(new InputStreamReader(
incoming.getInputStream()));
PrintWriter out = new PrintWriter(incoming.getOutputStream(), true);
int portData = 0;
while ((portData = in.read())!=35 )
data = data + (char)portData;
System.out.println(data);
System.out.println("Connection Closed");
} catch (Exception close) {
close.printStackTrace();
}
}
}
_____________________________________________________________
/*
* cardReader.java
*
*/
package allsec;
import java.awt.Panel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
import java.sql.*;
import javax.swing.JOptionPane;
/**
*
*/
public class cardReader extends Thread{
private static Connection con;
private static Socket client ;
private InetAddress moduleIP;
private int modulePortNo;
private static CallableStatement cstmt;
private static ResultSet rs;
static {
try {
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://xxx.x.xx.xxx:xxxx;datab
aseName=xxxx;","xx","");
cstmt = con.prepareCall("{ call proc_empinout(?) }");
} catch(SQLException sql){
JOptionPane.showMessageDialog(new Panel(),"Error while Connectiong to SQL Server","SQL Error",JOptionPane.ERROR_MESSAGE);
}
}
/**Creates a new instance of reader */
public cardReader(InetAddress ip,int portNo) {
moduleIP = ip;
modulePortNo = portNo;
try {
client = new Socket(moduleIP,modulePortNo);
} catch(IOException io) {
JOptionPane.showMessageDialog(new Panel(),"Error while Establishing Connection","IO Error",JOptionPane.INFORMATION_MESSAGE);
}
}
/** run method */
public void run() {
try {
BufferedReader portReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
String swipeData = "";
int portData = 0;
while (!client.isClosed()) {
while((portData=portReader.read())!=35) {
swipeData = swipeData+(char)portData;
}
String swipecardno = swipeData.substring(swipeData.indexOf(',')+1);
cstmt.setString(1, swipecardno);
cstmt.execute()
TEXT
Uploading file and scanning for virus...
Please Wait