Valhalla Legends Forums Archive | .NET Platform | [C#] Server/Client + Controlling Of Generic Media Player

AuthorMessageTime
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!
January 27, 2008, 2:57 AM
BreW
[quote author=Clan CDH link=topic=16055.msg161782#msg161782 date=1164480555]
and VB6 wasn't my first language, I was using it because it's "Basic" and quick to code in.
[/quote]
[quote author=Clan CDH link=topic=17284.msg175993#msg175993 date=1201402660]
My first language was VB
[/quote]
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.
January 27, 2008, 4:44 AM
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.
January 27, 2008, 5:13 AM
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
January 27, 2008, 3:20 PM
Clan CDH
For the client I am working on, it will not compile due to this error:
[QUOTE]Error  'GetSocket' does not implement interface member 'System.IDisposable.Dispose()'
[/QUOTE]

And here is my code so far:
[QUOTE]namespace 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;
    }
}
[/QUOTE]
January 31, 2008, 4:07 AM
Quarantine
I think it's pretty obvious, you inherit an interface but don't implement all the members. Implement Dispose(..)
January 31, 2008, 4:15 AM
Myndfyr
[quote author=Warrior link=topic=17284.msg176043#msg176043 date=1201752900]
I think it's pretty obvious, you inherit an interface but don't implement all the members. Implement Dispose(..)
[/quote]
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.
January 31, 2008, 3:59 PM
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.
February 4, 2008, 2:02 AM
Myndfyr
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.
February 4, 2008, 5:15 AM
Clan CDH
[quote author=MyndFyre[vL] link=topic=17284.msg176104#msg176104 date=1202102143]
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.
[/quote]

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.
February 5, 2008, 4:54 AM
Myndfyr
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));
February 5, 2008, 3:28 PM

Search