Skip to content

Instantly share code, notes, and snippets.

@cthree
Created November 28, 2012 13:20
Show Gist options
  • Save cthree/4161228 to your computer and use it in GitHub Desktop.
Save cthree/4161228 to your computer and use it in GitHub Desktop.
Example crashes CocoaAsyncSocket in rubymotion
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@payload = "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250\r\nMAN: ssdp:discover\r\nST: upnp:rootdevice\r\n"
@socket = GCDAsyncUdpSocket.alloc.initWithDelegate(self, delegateQueue:Dispatch::Queue.main)
@socket.bindToPort(1900, error:nil)
@socket.beginReceiving(nil)
puts "Socket Ready"
@socket.sendData(@payload.dataUsingEncoding(NSUTF8StringEncoding),
toHost:"239.255.255.250",
port:1900,
withTimeout:-1,
tag:0)
puts "SSDP M-SEARCH Message Sent"
true
end
def udpSocket(socket, didReceiveData:data, fromAddress:address, withFilterContext:filterContext)
puts "Message Received: #{data}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment