I have a badge reader which has an IP address and TCP port assigned to it. I can telnet into the IP and port and see the badge number every time it reads one. The session stays open and just sends a badge number and newline on every read. I want to do something similar in C#, but cannot figure out the best way to do it.
I've used TCPClient and Socket classes, but the best I can do is read the first badge and that's all. I've done it blocking and async, but again I can only read the first badge and then the code continues.
My main questions are:
1 - Will I need a thread to continually go back to a read state after every read? I was hoping there was something built in so I wouldn't have to do that.
2 - If I do go the threading route, will I need to close and re-establish the TCP session every time for a read, or just keep the session open and read new data?
Otherwise, are there better ways of doing it?
Any help is greatly appreciated.
Thanks,
David
Update:
Wow Sergey... You went right by the point there. Sometimes I wonder if people answer something without even halfway reading the question.
Thanks for the info and link Zoltan.
I can capture all bytes, and am basically getting a 6 digit number and a carriage return. That's all good. I can even configure the device to send me different data and formats. No problem there. I am just looking for a way in C# to open a TCP/IP connection to something and read every time it sends data.
I dont know if I need a thread to keep it actively reading for data or what.