Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't find roku on local network with C# code

I'm trying to learn how to use some of the Roku ECP by coding a web app version of the roku remote. I want to find the roku through a network call/listener, but my code isn't working. Using wireshark I can see my call leave my machine, but there is no response from the roku except for the standard 'i am here' broadcast it makes every 20 minutes or so. Since the roku isn't responding to my call, I assume I've done that part of the code incorrectly. I'm not sure about the listener section of my code either. If anyone has any idea what I've done wrong, I'd greatly appreciate the feedback. The way I've structured the methods, the HearRoku method initiates the CallRoku method

Thanks in advance
Charles

public class FindRoku
{
private static void CallRoku()
{
// configure sending socket
Socket sending_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
// set ssdp address and port
IPAddress receivingAddress = IPAddress.Parse("192.168.2.255");
IPEndPoint receivingEndpoint = new IPEndPoint(receivingAddress, 1900);

// write the request message
var request = new StringBuilder();
request.AppendLine("M-SEARCH * HTTP/1.1");
request.AppendLine("HOST: 239.255.255.250:1900");
request.AppendLine("MAN: \"ssdp:discover\"");
request.AppendLine("ST: roku:ecp");
request.AppendLine("");
string textToSend = request.ToString();

// encode the request into bytes
byte[] send_buffer = Encoding.ASCII.GetBytes(textToSend);

// send call
sending_socket.SendTo(send_buffer, receivingEndpoint);
}


public static IPAddress HearRoku()
{
CallRoku();

IPAddress rokuIP = null;
int listenPort = 60000;

UdpClient listener = new UdpClient(listenPort);
IPEndPoint listenerEP = new IPEndPoint(IPAddress.Any, listenPort);
string receivedData;
byte[] receiveByteArray;

receiveByteArray = listener.Receive(ref listenerEP);
receivedData = Encoding.ASCII.GetString(receiveByteArray, 0, receiveByteArray.Length);


//Need to add code to parse the receivedData to get the roku IPaddress. But untill I know the format I can't do it just yet.
return rokuIP;
}
}
0 Kudos
3 REPLIES 3
Romans_I_XVI
Roku Guru

Re: Can't find roku on local network with C# code

I don't know C# at all so I won't be much help. But I can tell you that I was able to get my app working with Java based on this example.
http://stackoverflow.com/questions/2840 ... -with-java

Hope that helps some.
0 Kudos
EnTerr
Roku Guru

Re: Can't find roku on local network with C# code

You are broadcasting to 192.168.2.255, why?
That's not what RTFM said.
0 Kudos
TheEndless
Channel Surfer

Re: Can't find roku on local network with C# code

I know you said this was a learning exercise, but you should be aware that even if you do get it working, it'll only work if your IIS server is running on the same network as your Roku, which severely limits its usability.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.