Method: EventMachine::Connection#send_data
- Defined in:
- lib/em/connection.rb
#send_data(data) ⇒ Object
Call this method to send data to the remote end of the network connection. It takes a single String argument, which may contain binary data. Data is buffered to be sent at the end of this event loop tick (cycle).
When used in a method that is event handler (for example, #post_init or #connection_completed, it will send data to the other end of the connection that generated the event. You can also call #send_data to write to other connections. For more information see The Chat Server Example in the EventMachine tutorial.
If you want to send some data and then immediately close the connection, make sure to use #close_connection_after_writing instead of #close_connection.
322 323 324 325 326 327 |
# File 'lib/em/connection.rb', line 322 def send_data data data = data.to_s size = data.bytesize if data.respond_to?(:bytesize) size ||= data.size EventMachine::send_data @signature, data, size end |