Hello, I'm trying to communicate from windows pc with Nfcgate server, I have not decided yet which is the best approach.
Can you please advise? below is an attempt I have made
def communicate_with_card(self, apdu):
r = readers()
if len(r) == 0:
self.log("No smart card readers detected.", tag="SmartCard")
return None
try:
connection = r[0].createConnection()
connection.connect()
response, sw1, sw2 = connection.transmit(apdu)
return response + [sw1, sw2]
except NoCardException:
self.log("No smart card inserted.", tag="SmartCard")
return None
def handle(self):
# Existing handle setup code remains unchanged
while True:
try:
# Existing code to read data from the socket remains unchanged
# Here, integrate smart card communication
# Convert data to APDU format if necessary
apdu = list(data) # Ensure it's in the correct format for pyscard
card_response = self.communicate_with_card(apdu)
if card_response is not None:
self.log(f"Card response: {card_response}", tag="SmartCard")
# Modify this part to send the card's response back
# For example, you might send it directly back to the requester or to all clients in a session
# This is a placeholder; adapt it to your needs
self.wfile.write(struct.pack('!I', len(card_response)) + bytes(card_response))
else:
self.log("Error communicating with the card.", tag="SmartCard")
# Break or continue based on your application's logic
except socket.timeout:
# Existing timeout handling remains unchanged
# Existing finish method remains unchanged