• Welcome to Valhalla Legends Archive.
 

[C#] Server/Client + Controlling Of Generic Media Player

Started by Clan CDH, January 26, 2008, 08:57 PM

Previous topic - Next topic

Clan CDH

My first language was VB, I soon forgot the language after I took a course of Java at my school.  I found it to be quite interesting and much better.  However, I started doing quite a bit of C# and have much more experience in it.  But I'm not too sure as how to go about this next program I plan on writing.

So here is what I want to do.  I wish to simply set up a Server/Client interface using C#, and then possibly figure out how to control a media player such as Winamp (i.e. like FoxyTunes).


Any help/suggestions is much appreciated!

brew

Quote from: Clan CDH on November 25, 2006, 12:49 PM
and VB6 wasn't my first language, I was using it because it's "Basic" and quick to code in.
Quote from: Clan CDH on January 26, 2008, 08:57 PM
My first language was VB
Found that somewhat interesting

So anyways,
Uh, what? A server/client interface using C#? Do you mean that you want to make a client and server with winsock or something? You're pretty vague.
And then "possibly figure out how to control a media player". For that, you can use SendMessage. You can easily disassemble your media player and find the HMENU param it passes to createwindow to make the buttons and use that for the wparam in your sendmessage call.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Clan CDH

Yeah, I was really immature at the time when I posted that and I lied a lot.


My apologies.  And I just want the client to send commands I had pre-defined in my code.

Something such as when the client says "doMsgBox" and the server looks something like this:

if(command == "doMsgBox")
{
     MessageBox(etc...)
}

And thanks for the suggestion on the Media Player.


Thanks again.

brew

It wasn't the lie that was interesting, it's the statement itself. Why would you care what your first language is?

As for the server/client interface you speak of, is it over a network? over the intertubes? between two processes on the localhost? You should take a look at winsocking (I think it's System.Net.Sockets).
You can find out more about it at http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.aspx.

Your goal for the client is to:
1. Create the socket (socket S = null;)
2. Connect to the remote server (the Connect method of the socket)
3. Send the command necessary (the Send method)

Your goal for the server is to:
1. Create the socket
2. Listen for any incoming connections
3. Accept it
4. When a command is received, parse.
5. Perform the command
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Clan CDH

For the client I am working on, it will not compile due to this error:
QuoteError  'GetSocket' does not implement interface member 'System.IDisposable.Dispose()'

And here is my code so far:
Quotenamespace firstClient

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // In this code example, use a hard-coded
            // IP address and message.
            getsocket(Connectsocket(textHost.Text, Int32.Parse(textPort.Text)));
        }
    }
}
public class GetSocket : IDisposable
{
    private static Socket ConnectSocket(string server, int port)
    {
        Socket s = null;
        IPHostEntry hostEntry = null;

        // Get host related information.
        hostEntry = Dns.GetHostEntry(server);

        // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
        // an exception that occurs when the host IP Address is not compatible with the address family
        // (typical in the IPv6 case).
        foreach (IPAddress address in hostEntry.AddressList)
        {
            IPEndPoint ipe = new IPEndPoint(address, port);
            Socket tempSocket =
                new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            tempSocket.Connect(ipe);

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

Warrior

I think it's pretty obvious, you inherit an interface but don't implement all the members. Implement Dispose(..)
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

MyndFyre

Quote from: Warrior on January 30, 2008, 10:15 PM
I think it's pretty obvious, you inherit an interface but don't implement all the members. Implement Dispose(..)
Or drop IDisposable.  Your class doesn't define any nonstatic members; it'll never be a disposable object.

You might be interested in a base connection class that I use for most of my Bnet/WoW connection classes:
http://www.jinxbot.net/CodeBrowse/JinxBot/JinxBot.Core/Net/ConnectionBase.cs.aspx

Released to public domain.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Clan CDH

Thanks for the idea MyndFyre, but I want to try and get this to work before I try something else out.  I haven't had any experience "disposing" of objects, so if someone could point me in the right direction upon how I could get this to work, I would be forever grateful.

MyndFyre

Lucky for you I just blogged about the Disposable pattern.  Hopefully it'll make a little more sense.

But, like I said, there's nothing to dispose in your class.  Since its only member is static, you never have an instance to dispose.  You should just drop IDisposable in this case.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Clan CDH

Quote from: MyndFyre[vL] on February 03, 2008, 11:15 PM
Lucky for you I just blogged about the Disposable pattern.  Hopefully it'll make a little more sense.

But, like I said, there's nothing to dispose in your class.  Since its only member is static, you never have an instance to dispose.  You should just drop IDisposable in this case.

My only problem is when I drop the IDisposable it returns the error "The name 'getsocket' does not exist in the current context."  And that blog confuses me somewhat, so I'm still a little puzzled.

MyndFyre

Well, for, C# is case-sensitive.  The second is that GetSocket isn't a method, it's a class.  The right way to call that function is:

GetSocket.ConnectSocket(textHost.Text, int.Parse(textPort.Text));
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.