PDA

View Full Version : Controlling my slimp3 with the multimedia keys on my keyboard



Jeff Shanholtz
2004-04-04, 21:26
I've got one of those MS Multimedia keyboards that's got play/pause, stop,
prev, and next buttons on it. It would be really cool if I could have them
perform those commands on my slimp3 (the keyboard allows you to configure
the keys to run arbitrary commands). Unfortunately this is complicated
slightly by the fact that this keyboard is on a windows machine and the
slimserver software is on a linux machine.

I could just have them execute an http link that I can get from the
slimserver web interface, but I'd really prefer to avoid having it launch a
browser window to accomplish the task. Is there any solution for doing this
currently? Alternatively, if it's not too complicated a task, I could
program it in perl or c++ if someone could point me to the information I
would need (or perhaps if there's no current solution I'll take this to the
dev group).

If anyone could provide some insight on this I would appreciate it!

Pat Farrell
2004-04-04, 21:38
At 12:26 AM 4/5/2004, Jeff Shanholtz wrote:
> Unfortunately this is complicated
>slightly by the fact that this keyboard is on a windows machine and the
>slimserver software is on a linux machine.


Sounds like a good reason to kill off another Windows machine :-)

>I could just have them execute an http link that I can get from the
>slimserver web interface, but I'd really prefer to avoid having it launch a
>browser window to accomplish the task. Is there any solution for doing this
>currently?

All you need is a program that talks to the Slimserver daemon.
You there are lots of commands, all you have to do is
open a socket to slimserverhost:9000 and talk.

>program it in perl or c++ if someone could point me to the information I
>would need

Not C++, but if you want to try it with perl or java or even C#,
and want more, holler off list. This problem begs for perl.

Pat

Jeff Shanholtz
2004-04-05, 20:37
I tried emailing you but for some reason I don't _think_ it went through
properly. Therefore despite your request for an off-list response, I'm
replying on-list...

On Mon, 05 Apr 2004 00:38:47 -0400, in
gmane.music.equipment.slimdevices.general you wrote:

> All you need is a program that talks to the Slimserver daemon.
> You there are lots of commands, all you have to do is open a socket to
> slimserverhost:9000 and talk.
>
>>program it in perl or c++ if someone could point me to the information
>>I would need
>
> Not C++, but if you want to try it with perl or java or even C#, and
> want more, holler off list. This problem begs for perl.

It just occurred to me that if I do it in perl, that probably means I'd
have to see a console window appear (at least, I'm not aware of how to
write a perl app that runs "silently"). So since I'm somewhat proficient at
C# maybe that's the way to go here. I was afraid I'd be in for some socket
programming (since I've never done it before), but maybe this will be a
good opportunity to learn a new skill.

I found a code sample for doing some socket programming in C# and I've
tried modifying it for use here but it seems to hang waiting for the
response. It was originally a sample for grabbing a web page, so I guess
http and telnet are different enough that this doesn't work right. Maybe
you can spot the problem or else if you have some sample code that would be
good too.

I appreciate your offer to help. Maybe if all goes well I can offer it up
for use by anyone in our community once it's done.


private static Socket connectSocket(string server, int port)
{
Socket s = null;
IPHostEntry iphe = null;

try
{
// Get host related information.
iphe = Dns.Resolve(server);

// Loop through the AddressList to obtain the supported AddressFamily.
This is to avoid
// an exception to be thrown if the host IP Address is not compatible
with the address family
// (typical in the IPv6 case).
foreach(IPAddress ipad in iphe.AddressList)
{
IPEndPoint ipe = new IPEndPoint(ipad, port);

Socket tmpS =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

tmpS.Connect(ipe);

if(tmpS.Connected)
{
s = tmpS;
break;
}
else
continue;
}
}

catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
return s;
}

private static string socketSendReceive(string server, int port, string
send)
{
//Set up variables and String to write to the server.
Encoding ASCII = Encoding.ASCII;
Byte[] ByteGet = ASCII.GetBytes(send);
Byte[] RecvBytes = new Byte[256];
String strRet = null;

// Create a socket connection with the specified server and port.
Socket s = connectSocket(server, port);

if (s == null)
return ("Connection failed");

// Send request to the server.
s.Send(ByteGet, ByteGet.Length, 0);

// Receive the server home page content.
Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);

// Read the first 256 bytes.
strRet = ASCII.GetString(RecvBytes, 0, bytes);

while (bytes > 0)
{
bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRet = strRet + ASCII.GetString(RecvBytes, 0, bytes);
}

return strRet;
}