Reputation: 498
I am creating an attendance marking system in using visual studio 2010 and Sql server 2008R2.And an RFID card for each members.I am using third party device AR800P-TCP as RFID reader,It has RJ45 port to connect with PC.i want to read data from card to my project using RJ45 port.How it possible. Write some code i tried is:
try
{
IPAddress ipAd = IPAddress.Parse("122.174.226.76");
/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 8001);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("The server is running at port 8001...");
Console.WriteLine("The local End point is :" +
myList.LocalEndpoint);
string sw = "The local End point is :" + myList.LocalEndpoint;
textBox1.Text = sw;
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
// Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
string sw1 = "Connection accepted from " + s.RemoteEndPoint;
textBox2.Text = sw1;
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Recieved...");
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(b[i]));
// string sw3 = Convert.ToChar(b[i])
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
/* clean up */
s.Close();
myList.Stop();
}
Upvotes: 0
Views: 3626
Reputation: 29028
First of all: RJ-45 is a hardware specification and not a software specification. So telling us the connector you are using is as helpful as telling us the size of the display or the length of the cable,...
Important is the software level. This means man need to know the protocol which is used for the the connection. I assume (from the name of your hardware) that it uses TCP/IP.
Check the provided MSDN - Socket Class link. It has a code example and some basic information for you how to setup a TCP/IP socket. Please read it!
Upvotes: 1