Sha256: a300550648b085e0f49108cc574b95f8e94223c7c664462f284613eed5b3a096

Contents?: true

Size: 1.09 KB

Versions: 43

Compression:

Stored size: 1.09 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))

require 'test/unit'
require 'rex/socket/udp'

class Rex::Socket::Udp::UnitTest < Test::Unit::TestCase

	def test_udp
		serv_port = 55432
		serv = Rex::Socket::Udp.create(
			'LocalHost' => '127.0.0.1',
			'LocalPort' => serv_port)

		begin
			assert_kind_of(Rex::Socket::Udp, serv, "valid Udp server instance")

			# Test connected socket
			concli = Rex::Socket::Udp.create(
				'PeerHost' => '127.0.0.1',
				'PeerPort' => serv_port)

			assert_equal('127.0.0.1', concli.peerhost, "matching peerhost")
			assert_equal(serv_port, concli.peerport, "matching peerport")
			assert_equal(2, concli.write('yo'), "write succeeded")

			data, host, port = serv.recvfrom

			assert_equal('yo', data, "read data match")
			assert_equal('127.0.0.1', host, "matching client host")

			# Test non-connected socket
			concli = Rex::Socket::Udp.create

			assert_equal(3, concli.sendto('bob', '127.0.0.1', serv_port), "sendto")
			data, host, port = serv.recvfrom
			assert_equal('bob', data, "read data match")
		ensure
			serv.close
		end
	end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/socket/udp.rb.ut.rb
librex-0.0.63 lib/rex/socket/udp.rb.ut.rb
librex-0.0.54 lib/rex/socket/udp.rb.ut.rb
librex-0.0.53 lib/rex/socket/udp.rb.ut.rb
librex-0.0.52 lib/rex/socket/udp.rb.ut.rb
librex-0.0.51 lib/rex/socket/udp.rb.ut.rb
librex-0.0.50 lib/rex/socket/udp.rb.ut.rb
librex-0.0.49 lib/rex/socket/udp.rb.ut.rb
librex-0.0.48 lib/rex/socket/udp.rb.ut.rb
librex-0.0.47 lib/rex/socket/udp.rb.ut.rb
librex-0.0.46 lib/rex/socket/udp.rb.ut.rb
librex-0.0.44 lib/rex/socket/udp.rb.ut.rb
librex-0.0.43 lib/rex/socket/udp.rb.ut.rb
librex-0.0.42 lib/rex/socket/udp.rb.ut.rb
librex-0.0.41 lib/rex/socket/udp.rb.ut.rb
librex-0.0.40 lib/rex/socket/udp.rb.ut.rb
librex-0.0.39 lib/rex/socket/udp.rb.ut.rb
librex-0.0.38 lib/rex/socket/udp.rb.ut.rb
librex-0.0.37 lib/rex/socket/udp.rb.ut.rb
librex-0.0.36 lib/rex/socket/udp.rb.ut.rb