@@ -290,6 +290,30 @@ private void CheckProtocol(string protocol)
290290 "Multicast protocols are not supported by socket type: " + m_options . SocketType ) ;
291291 }
292292 break ;
293+ case Address . UdpProtocol :
294+ // UDP is supported for most socket types.
295+ switch ( m_options . SocketType )
296+ {
297+ case ZmqSocketType . Radio :
298+ case ZmqSocketType . Dish :
299+ case ZmqSocketType . Pub :
300+ case ZmqSocketType . Sub :
301+ case ZmqSocketType . Xpub :
302+ case ZmqSocketType . Xsub :
303+ case ZmqSocketType . Req :
304+ case ZmqSocketType . Rep :
305+ case ZmqSocketType . Push :
306+ case ZmqSocketType . Pull :
307+ case ZmqSocketType . Pair :
308+ case ZmqSocketType . Dealer :
309+ case ZmqSocketType . Router :
310+ // All is well
311+ break ;
312+ default :
313+ throw new ProtocolNotSupportedException (
314+ "UDP protocol is not supported by socket type: " + m_options . SocketType ) ;
315+ }
316+ break ;
293317 default :
294318 throw new ProtocolNotSupportedException ( "Invalid protocol: " + protocol ) ;
295319 }
@@ -619,6 +643,26 @@ public void Bind(string addr)
619643 throw ;
620644 }
621645
646+ m_options . LastEndpoint = listener . Address ;
647+ AddEndpoint ( addr , listener , null ) ;
648+ break ;
649+ }
650+ case Address . UdpProtocol :
651+ {
652+ var listener = new Transports . Udp . UdpListener ( ioThread , this , m_options ) ;
653+
654+ try
655+ {
656+ listener . SetAddress ( address ) ;
657+ m_port = listener . Port ;
658+ }
659+ catch ( NetMQException ex )
660+ {
661+ listener . Destroy ( ) ;
662+ EventBindFailed ( addr , ex . ErrorCode ) ;
663+ throw ;
664+ }
665+
622666 m_options . LastEndpoint = listener . Address ;
623667 AddEndpoint ( addr , listener , null ) ;
624668 break ;
@@ -832,15 +876,22 @@ public void Connect(string addr)
832876 paddr . Resolved . Resolve ( address , m_options . IPv4Only ) ;
833877 break ;
834878 }
879+ case Address . UdpProtocol :
880+ {
881+ paddr . Resolved = new Transports . Udp . UdpAddress ( ) ;
882+ paddr . Resolved . Resolve ( address , m_options . IPv4Only ) ;
883+ break ;
884+ }
835885 }
836886
837887 // Create session.
838888 SessionBase session = SessionBase . Create ( ioThread , true , this , m_options , paddr ) ;
839889 Assumes . NotNull ( session ) ;
840890
841- // PGM does not support subscription forwarding; ask for all data to be
891+ // PGM and UDP do not support subscription forwarding; ask for all data to be
842892 // sent to this pipe.
843- bool icanhasall = protocol == Address . PgmProtocol || protocol == Address . EpgmProtocol ;
893+ bool icanhasall = protocol == Address . PgmProtocol || protocol == Address . EpgmProtocol
894+ || protocol == Address . UdpProtocol ;
844895 Pipe ? newPipe = null ;
845896
846897 if ( ! m_options . DelayAttachOnConnect || icanhasall || m_options . SocketType == ZmqSocketType . Peer )
0 commit comments