I want to end the Ipv6 socket in Python, I do it like this :
#! / Usr / bin / env python import import import import socket host = 'fe80 :: 225: b3ff: fe26: 576' s = socket.socket (socket.AFINAT6, socket.ScKDGRAM) bitband (host, 50000) )
but it failed:
socket.error: (22, 'invalid argument')?
Can anyone help me? Thanks!
I repeat it again, but still can not work
& gt; & Gt; Host = 'fe80 :: 225: b3ff: fe26: 576' & gt; & Gt; Sa = socket.socket (socket.afiqt6, socket.SOCCDARAM) & gt; & Gt; & Gt; Res = socket.getaddrinfo (host, port, socket.AF_UNSPEC, socket.SOCDRAMM, 0, socket.aI_ PASSIVE) & gt; & Gt; Family, sextape, proto, cannam, socadrant = rs [0] & gt; & Gt; & Gt; Print sweater ('fe80 :: 225: b3ff: fe26: 576', 50001, 0, 0) & gt; & Gt; ; & Gt; Slab (Socied) Traceback (the most recent call final): In the file "& lt; stdin & gt;", in line 1,? In the file "& lt; string & gt;", line 1, in bind socket Terror: (22, 'invalid argument')
first issue
You should use a bitband where the secoder is obtained from Getaddrinfo
& gt; & Gt; & Gt; HOST = 'localhost' & gt; & Gt; & Gt; Ports = 50007 & gt; & Gt; & Gt; Res = socket.getaddrinfo (HOST, PORT, socket.AF_UNSPEC, socket.SOCK_DGRAM, 0, socket. AI_PASSIVE) & gt; & Gt; & Gt; Family, sock-type, proto, cannam, soceder = res [1] & gt; & Gt; & Gt; Proto 17 & gt; & Gt; & Gt; Sockaddr ('fe80 :: 1% lo0', 50007, 0, 1)
Second digit
If you see the example socket In the document given in the document
Socket accepts three arguments
socket ([family, type [, Proto]]]]
According to the document
create a new socket using the given address family, socket type and protocol number. Family should be AF_INET (default), AF_INET6 or AF_UNIX. Socket type SOCK_STREAM ( Default), SOCK_DGRAM, or perhaps other "SOCK_" constants. The protocol number is usually zero and can be left in that position.
And if you want to proto If you use getaddressinfo to get the value, the value is different from the default 0
But when I execute the following, I get a different protocol. - 17. You may also want to check it .
And certainly socket.has _ipv6 is true for me.
Comments
Post a Comment