creates TCP/IP server sockets for host and port. host is optional.
If no block given, it returns an array of listening sockets.
If a block is given, the block is called with the sockets. The value of the block is returned. The socket is closed when this method returns.
If port is 0, actual port number is chosen dynamically. However all sockets in the result has same port number.
# tcp_server_sockets returns two sockets. sockets = Socket.tcp_server_sockets(1296) p sockets #=> [#<Socket:fd 3>, #<Socket:fd 4>] # The sockets contains IPv6 and IPv4 sockets. sockets.each {|s| p s.local_address } #=> #<Addrinfo: [::]:1296 TCP> # #<Addrinfo: 0.0.0.0:1296 TCP> # IPv6 and IPv4 socket has same port number, 53114, even if it is chosen dynamically. sockets = Socket.tcp_server_sockets(0) sockets.each {|s| p s.local_address } #=> #<Addrinfo: [::]:53114 TCP> # #<Addrinfo: 0.0.0.0:53114 TCP> # The block is called with the sockets. Socket.tcp_server_sockets(0) {|sockets| p sockets #=> [#<Socket:fd 3>, #<Socket:fd 4>] }
Creates UDP/IP sockets for a UDP server.
If no block given, it returns an array of sockets.
If a block is given, the block is called with the sockets. The value of the block is returned. The sockets are closed when this method returns.
If port is zero, some port is chosen. But the chosen port is used for the all sockets.
# UDP/IP echo server Socket.udp_server_sockets(0) {|sockets| p sockets.first.local_address.ip_port #=> 32963 Socket.udp_server_loop_on(sockets) {|msg, msg_src| msg_src.reply msg } }
Receive UDP/IP packets from the given sockets. For each packet received, the block is called.
The block receives msg and msg_src. msg is a string which is the payload of the received packet. msg_src is a Socket::UDPSource
object which is used for reply.
Socket.udp_server_loop
can be implemented using this method as follows.
udp_server_sockets(host, port) {|sockets| loop { readable, _, _ = IO.select(sockets) udp_server_recv(readable) {|msg, msg_src| ... } } }
creates a UNIX server socket on path
If no block given, it returns a listening socket.
If a block is given, it is called with the socket and the block value is returned. When the block exits, the socket is closed and the socket file is removed.
socket = Socket.unix_server_socket("/tmp/s") p socket #=> #<Socket:fd 3> p socket.local_address #=> #<Addrinfo: /tmp/s SOCK_STREAM> Socket.unix_server_socket("/tmp/sock") {|s| p s #=> #<Socket:fd 3> p s.local_address #=> # #<Addrinfo: /tmp/sock SOCK_STREAM> }
Returns WIN32OLE
object for a specific dispatch or dual interface specified by iid.
ie = WIN32OLE.new('InternetExplorer.Application') ie_web_app = ie.ole_query_interface('{0002DF05-0000-0000-C000-000000000046}') # => WIN32OLE object for dispinterface IWebBrowserApp
Returns the value of the local variable symbol
.
def foo a = 1 binding.local_variable_get(:a) #=> 1 binding.local_variable_get(:b) #=> NameError end
This method is the short version of the following code:
binding.eval("#{symbol}")
Yields each frame of the current execution stack as a backtrace location object.
obj can be an instance of InternalObjectWrapper
.
Note that you should not use this method in your application.
The file name and line number of the caller of the caller of this method.
depth
is how many layers up the call stack it should go.
e.g.,
def a; Gem.location_of_caller
; end a #=> [“x.rb”, 2] # (it’ll vary depending on file name and line number)
def b; c; end def c; Gem.location_of_caller(2)
; end b #=> [“x.rb”, 6] # (it’ll vary depending on file name and line number)
Returns the latest release version of RubyGems.
Like Enumerable#select
, but chains operation to be lazy-evaluated.
Generates a random prime number of bit length bits. If safe is set to true
, generates a safe prime. If add is specified, generates a prime that fulfills condition p % add = rem
.
Translates and dispatches Windows message.
Returns the X509 certificate chain (an array of strings) for the session’s socket peer, or nil
if none.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.
Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of binary_operator_loc.