MCPcopy Create free account
hub / github.com/andreikop/python-ws-discovery / _sendMsg

Method _sendMsg

wsdiscovery/threaded.py:261–285  ·  view source on GitHub ↗
(self, msg)

Source from the content-addressed store, hash-verified

259 self._observer.envReceived(env, addr)
260
261 def _sendMsg(self, msg):
262 data = createSOAPMessage(msg.getEnv()).encode("UTF-8")
263
264 if msg.msgType() == UDPMessage.UNICAST:
265 self._uniOutSocket.sendto(data, (msg.getAddr(), msg.getPort()))
266 if self._capture:
267 self._capture.write(
268 "%i SEND %s:%s TS=%s\n" % (self._seqnum, msg.getAddr(), msg.getPort(), time.time() - self.t0))
269 self._capture.write(dom2Str(data))
270 self._seqnum += 1
271 else:
272 for addr, sock in self._multiOutUniInSockets.items():
273 try:
274 sock.sendto(data, (msg.getAddr(), msg.getPort()))
275 except OSError as e:
276 # sendto will fail for interfaces that do not support multicast or are not up.
277 # An example of the first case is a wireguard vpn interface.
278 # In either case just log as debug and ignore the error.
279 logger.debug("Interface for %s does not support multicast or is not UP.\n\tOSError %s",
280 socket.inet_ntoa(sock.getsockopt(self._get_ip_proto(), self._get_multicast(), 4)), e)
281 if self._capture:
282 self._capture.write("%i SEND %s:%s iface=%s TS=%s\n" % (
283 self._seqnum, msg.getAddr(), msg.getPort(), addr, time.time() - self.t0))
284 self._capture.write(dom2Str(data))
285 self._seqnum += 1
286
287 def _sendPendingMessages(self):
288 """Method sleeps, if nothing to do"""

Callers 1

_sendPendingMessagesMethod · 0.95

Calls 8

_get_ip_protoMethod · 0.95
_get_multicastMethod · 0.95
createSOAPMessageFunction · 0.85
dom2StrFunction · 0.85
getEnvMethod · 0.80
msgTypeMethod · 0.80
getAddrMethod · 0.80
getPortMethod · 0.80

Tested by

no test coverage detected