Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/io/gram_server.rb
Views: 11780
# -*- coding: binary -*-1require 'thread'23module Rex4module IO56###7#8# This mixin provides the framework and interface for implementing a datagram9# server that can handle incoming datagrams. Datagram servers include this mixin10#11###12module GramServer1314##15#16# Abstract methods17#18##1920##21#22# Default server monitoring and client management implementation follows23# below.24#25##262728#29# This callback is notified when a client connection has data that needs to30# be processed.31#32def dispatch_request(client, data)33if (dispatch_request_proc)34dispatch_request_proc.call(client, data)35end36end3738#39# This callback is notified when data must be returned to the client40# @param client [Socket] Client/Socket to receive data41# @param data [String] Data to be sent to client/socket42def send_response(client, data)43if (send_response_proc)44send_response_proc.call(client, data)45else46client.write(data)47end48end4950#51# Start monitoring the listener socket for connections and keep track of52# all client connections.53#54def start55self.listener_thread = Rex::ThreadFactory.spawn("GramServerListener", false) {56monitor_listener57}58end5960#61# Terminates the listener monitoring threads and closes all active clients.62#63def stop64self.listener_thread.kill65end6667#68# This method waits on the server listener thread69#70def wait71self.listener_thread.join if self.listener_thread72end7374##75#76# Callback procedures.77#78##7980#81# This callback procedure can be set and will be called when clients82# have data to be processed.83#84attr_accessor :dispatch_request_proc, :send_response_proc8586attr_accessor :listener_thread# :nodoc:878889end9091end92end93949596