Updated RubySpec source to 55122684.
[rbx.git] / spec / frozen / 1.8 / library / socket / udpsocket / send_spec.rb
blobee5613c22d4b469622536389b202440d4d0ff17d
1 require File.dirname(__FILE__) + '/../../../spec_helper'
2 require File.dirname(__FILE__) + '/../fixtures/classes'
4 describe "UDPSocket.send" do
5   before :each do
6     @ready = false
7     @server_thread = Thread.new do
8       @server = UDPSocket.open
9       @server.bind(nil, SocketSpecs.port)
10       @ready = true
11       @msg = @server.recvfrom(64)
12       @server.close
13     end
14     Thread.pass while @server_thread.status and !@ready
15   end
16   
17   it "sends data in ad hoc mode" do
18     @socket = UDPSocket.open
19     @socket.send("ad hoc", 0, SocketSpecs.hostname,SocketSpecs.port)
20     @socket.close
21     @server_thread.join
22       
23     @msg[0].should == "ad hoc"
24     @msg[1][0].should == "AF_INET"
25     @msg[1][1].should be_kind_of(Fixnum)
26     @msg[1][3].should == "127.0.0.1"
27   end
29   it "sends data in connection mode" do
30     @socket = UDPSocket.open
31     @socket.connect(SocketSpecs.hostname,SocketSpecs.port)
32     @socket.send("connection-based", 0)
33     @socket.close
34     @server_thread.join
35     
36     @msg[0].should == "connection-based"
37     @msg[1][0].should == "AF_INET"
38     @msg[1][1].should be_kind_of(Fixnum)
39     @msg[1][3].should == "127.0.0.1"
40   end
41 end