socket & http about ipv4 or ipv6

Recently, i had some problems about ipv4 and ipv6.  I simplely introducing my problems, i use my iphone(iphone 11/15.3.1) to establish with device A by socket(swift/ Network.framework),  but the premise is that iphone needs to connect device A's wifi.
 When I connect device A's wifi , i found there are one ipv4 and two ipv6s.

My iphone establishs with device A successful by socket, the remote ip is ipv6, and
iphone uses one of ipv6s automatically. Device A sends me device B's ipaddress, and now i need use my iphone to establish with B synchronously, but i find iphone using another ipv6 address. B's firewall blocked because ip is different from client ipaddress when connecting with device A . I don't know why iphone using another ipv6 to establish with device B, this is question A. Now i resolved the question through "connection.currentPath?.localEndpoint" and requiredLocalEndpoint, I can get client ipaddress when connecing with device A through "connection.currentPath?.localEndpoint", and then i set "requiredLocalEndpoint" the same as the ip i just got, but needs to modify port when connecting with device B.

Device B sends my iphone mutible data that contain urls, when my iphone request s urls through alamofire or pure nsurlsession, i found that my iphone's client ipaddress was ipv4, so device B's firewall blocked. I don't know how to set https clientaddress and why iphone uses ipv4 but socket was ipv6.

socket & http about ipv4 or ipv6
 
 
Q