Sha256: 37d744965818a92adde29a86b5cacec2d87d74b8d4a11a7ea8a227baca4a570a

Contents?: true

Size: 1.05 KB

Versions: 35

Compression:

Stored size: 1.05 KB

Contents

require 'rex/socket'
require 'rex/socket/tcp'
require 'rex/io/stream_server'

###
#
# This class provides methods for interacting with a TCP server.  It
# implements the Rex::IO::StreamServer interface.
#
###
module  Rex::Socket::TcpServer

	include Rex::Socket
	include Rex::IO::StreamServer

	##
	#
	# Factory
	#
	##

	#
	# Creates the server using the supplied hash.
	#
	def self.create(hash = {})
		hash['Proto'] = 'tcp'
		hash['Server'] = true
		self.create_param(Rex::Socket::Parameters.from_hash(hash))
	end

	#
	# Wrapper around the base class' creation method that automatically sets
	# the parameter's protocol to TCP and sets the server flag to true.
	#
	def self.create_param(param)
		param.proto  = 'tcp'
		param.server = true
		Rex::Socket.create_param(param)
	end

	#
	# Accepts a child connection.
	#
	def accept(opts = {})
		t = super()

		# jRuby compatibility
		if t.respond_to?('[]')
			t = t[0]
		end

		if (t)
			t.extend(Rex::Socket::Tcp)
			t.context = self.context

			pn = t.getpeername

			t.peerhost = pn[1]
			t.peerport = pn[2]
		end

		t
	end

end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
librex-0.0.35 lib/rex/socket/tcp_server.rb
librex-0.0.34 lib/rex/socket/tcp_server.rb
librex-0.0.33 lib/rex/socket/tcp_server.rb
librex-0.0.32 lib/rex/socket/tcp_server.rb
librex-0.0.31 lib/rex/socket/tcp_server.rb
librex-0.0.30 lib/rex/socket/tcp_server.rb
librex-0.0.29 lib/rex/socket/tcp_server.rb
librex-0.0.28 lib/rex/socket/tcp_server.rb
librex-0.0.27 lib/rex/socket/tcp_server.rb
librex-0.0.26 lib/rex/socket/tcp_server.rb
librex-0.0.25 lib/rex/socket/tcp_server.rb
librex-0.0.23 lib/rex/socket/tcp_server.rb
librex-0.0.21 lib/rex/socket/tcp_server.rb
librex-0.0.19 lib/rex/socket/tcp_server.rb
librex-0.0.17 lib/rex/socket/tcp_server.rb