Lazily create the socket.
(self)
| 236 | |
| 237 | @property |
| 238 | def socket(self): |
| 239 | """ |
| 240 | Lazily create the socket. |
| 241 | """ |
| 242 | if not hasattr(self, "_socket"): |
| 243 | # create a new one |
| 244 | self._socket = self.context.socket(zmq.REQ) |
| 245 | if hasattr(zmq, "RECONNECT_IVL_MAX"): |
| 246 | self._socket.setsockopt(zmq.RECONNECT_IVL_MAX, 5000) |
| 247 | |
| 248 | self._set_tcp_keepalive() |
| 249 | if self.master.startswith("tcp://["): |
| 250 | # Hint PF type if bracket enclosed IPv6 address |
| 251 | if hasattr(zmq, "IPV6"): |
| 252 | self._socket.setsockopt(zmq.IPV6, 1) |
| 253 | elif hasattr(zmq, "IPV4ONLY"): |
| 254 | self._socket.setsockopt(zmq.IPV4ONLY, 0) |
| 255 | self._socket.linger = self.linger |
| 256 | if self.id_: |
| 257 | self._socket.setsockopt(zmq.IDENTITY, self.id_) |
| 258 | self._socket.connect(self.master) |
| 259 | return self._socket |
| 260 | |
| 261 | def _set_tcp_keepalive(self): |
| 262 | if hasattr(zmq, "TCP_KEEPALIVE") and self.opts: |