The Satoshi client discovers the IP address and port of nodes in several different ways.
Nodes discover their own external address by various methods.
Nodes receive the callback address of remote nodes that connect to them.
Nodes makes DNS request to receive IP addresses.
Nodes can ...
Usually the issue is the Signature Verification algorithm used. Bitcoin uses double SHA-256 as the hashing algorithm for ECDSA, thus the Z value is the Double SHA-256 hash of the unsigned transaction. Looking at the Signature Hash Algorithm you're using:
Signature algorithm ALG_ECDSA_SHA_256 generates a 32-byte SHA-256 digest and signs/verifies the digest ...