Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 'Basic' Client /Server

'Basic' Client /Server

Scheduled Pinned Locked Moved C#
helptutorialquestioncsharpdatabase
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tdata
    wrote on last edited by
    #1

    Been looking for quite some time for the answer to my question. How do I do this in C#:

    //Note: Pseudo Code for example purposes only...
    [Client]
    SendToServer(ClientActions.Login, username, password);

    [Server]
    ReceiveRequest(Tag, pram1, pram2);
    if (tag == ClientActions.Login)
    {
    bool exUser = UserExist(pram1, pram2);
    if (exUser)
    SendToClient(ServerAction.Exist);
    else
    SendToClient(ServerAction.NotExist);
    }

    [Client]
    ReceiveResponse(Response);
    if (Response == ServerAction.Exist)
    // Display message of response
    else
    // Display message of response

    I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

    L P RaviBeeR T 5 Replies Last reply
    0
    • T tdata

      Been looking for quite some time for the answer to my question. How do I do this in C#:

      //Note: Pseudo Code for example purposes only...
      [Client]
      SendToServer(ClientActions.Login, username, password);

      [Server]
      ReceiveRequest(Tag, pram1, pram2);
      if (tag == ClientActions.Login)
      {
      bool exUser = UserExist(pram1, pram2);
      if (exUser)
      SendToClient(ServerAction.Exist);
      else
      SendToClient(ServerAction.NotExist);
      }

      [Client]
      ReceiveResponse(Response);
      if (Response == ServerAction.Exist)
      // Display message of response
      else
      // Display message of response

      I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use Remoting or WCF. You can create your own method and your own object for sending/receiving. Remoting : http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=62[^] WCF : http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication[^]

      1 Reply Last reply
      0
      • T tdata

        Been looking for quite some time for the answer to my question. How do I do this in C#:

        //Note: Pseudo Code for example purposes only...
        [Client]
        SendToServer(ClientActions.Login, username, password);

        [Server]
        ReceiveRequest(Tag, pram1, pram2);
        if (tag == ClientActions.Login)
        {
        bool exUser = UserExist(pram1, pram2);
        if (exUser)
        SendToClient(ServerAction.Exist);
        else
        SendToClient(ServerAction.NotExist);
        }

        [Client]
        ReceiveResponse(Response);
        if (Response == ServerAction.Exist)
        // Display message of response
        else
        // Display message of response

        I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

        P Offline
        P Offline
        Paulo Zemek
        wrote on last edited by
        #3

        As said, use Remoting or WCF. But, you will not: SendToServer And then ReceiveResponse You will: CallMethod(parameters) And such method can have a return type, so you get the response automatically.

        1 Reply Last reply
        0
        • T tdata

          Been looking for quite some time for the answer to my question. How do I do this in C#:

          //Note: Pseudo Code for example purposes only...
          [Client]
          SendToServer(ClientActions.Login, username, password);

          [Server]
          ReceiveRequest(Tag, pram1, pram2);
          if (tag == ClientActions.Login)
          {
          bool exUser = UserExist(pram1, pram2);
          if (exUser)
          SendToClient(ServerAction.Exist);
          else
          SendToClient(ServerAction.NotExist);
          }

          [Client]
          ReceiveResponse(Response);
          if (Response == ServerAction.Exist)
          // Display message of response
          else
          // Display message of response

          I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

          RaviBeeR Offline
          RaviBeeR Offline
          RaviBee
          wrote on last edited by
          #4

          Along with the other replies, I strongly recommend using WCF to do this.  Imho it's easy, reliable and flexible. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          1 Reply Last reply
          0
          • T tdata

            Been looking for quite some time for the answer to my question. How do I do this in C#:

            //Note: Pseudo Code for example purposes only...
            [Client]
            SendToServer(ClientActions.Login, username, password);

            [Server]
            ReceiveRequest(Tag, pram1, pram2);
            if (tag == ClientActions.Login)
            {
            bool exUser = UserExist(pram1, pram2);
            if (exUser)
            SendToClient(ServerAction.Exist);
            else
            SendToClient(ServerAction.NotExist);
            }

            [Client]
            ReceiveResponse(Response);
            if (Response == ServerAction.Exist)
            // Display message of response
            else
            // Display message of response

            I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

            T Offline
            T Offline
            tdata
            wrote on last edited by
            #5

            Okay, so WCF is the way to go. And, as I said, it is Pseudo code. ^_^ It shows what I expect the server to do, not exactly what it will do. So, how would I go about using WCF with my example as the start? IE a simple Return of a Bool... I just need to see an example that doesn't rely on a string... ^_^ One more thing. How do you get it to listen for more than one thing. I would think it would have to do with the Channel... But not sure. Thank you for your prior help and for any further help you can provide. Nevermind, I figured it out, I think. You just add more Functions to the Interface... Now I just need to find a cheap Windows Server to test it on... EDIT:: I can't seem to get it to report errors other than System.ServiceModel errors. I missed a MySQL error because All I got from the Debugger was that an Internal error occurred... Not a big deal, but a bit annoying...

            modified on Monday, February 22, 2010 8:18 PM

            1 Reply Last reply
            0
            • T tdata

              Been looking for quite some time for the answer to my question. How do I do this in C#:

              //Note: Pseudo Code for example purposes only...
              [Client]
              SendToServer(ClientActions.Login, username, password);

              [Server]
              ReceiveRequest(Tag, pram1, pram2);
              if (tag == ClientActions.Login)
              {
              bool exUser = UserExist(pram1, pram2);
              if (exUser)
              SendToClient(ServerAction.Exist);
              else
              SendToClient(ServerAction.NotExist);
              }

              [Client]
              ReceiveResponse(Response);
              if (Response == ServerAction.Exist)
              // Display message of response
              else
              // Display message of response

              I am trying to setup a MultiPerson game using C# as my primary. Currently I have the client access the database directly because I have found no tutorials explaining how to this sort of thing. Mostly I have found Chat servers which do not help me figure this problem out. I have been able to do the above using alternate means, but since I will need to do more than send a few simple strings, I have no clue how to do it... My main issue is figuring out how to get both the client and the server to know how to deal with whatever comes down the pipe. My progression after the above would have been to ask the server for the userdata and have the server send a List object back. But I don't know how to do it. I would appreciate any and all help for this.

              T Offline
              T Offline
              tdata
              wrote on last edited by
              #6

              Seems I do need more help after all. I have 2 main issues. The first is that I get different results when using the .NET 3.5 Framework and the .NET 4.0 Framework. The app functions correctly in 4.0 but returns a few odd things in 3.5. While all in all it doesn't matter, I'm using 4.0 as the primary anyway, it does pose a problem on the end-user. 3.5 is standard but 4.0 is in beta4 so most will not touch it. My second problem is this:

              System.ServiceModel.CommunicationObjectFaultedException: The communication object,
              System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state.
              at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
              at System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()
              at Impur.Game.Network.Server.Program.Main(String[] args)

              Now, I understand the error. It is because I went the Using route when making my ServiceHost. My problem is that I don't know hot to do it another way. Now, my app works perfectly on my computer, but gives that error on my Dev Tester's computer. Here is the code I use. Maybe you can tell me how to do it another way:

                          using (ServiceHost host = new ServiceHost(
                              typeof(Actions),
                              new Uri\[\]{
                              new Uri("http://localhost:8000"),
                              new Uri("net.pipe://localhost")
                          }))
              

              EDIT:: Fixed the Second problem and have now encountered:

              System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8000/. Your
              process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353
              for details). ---> System.Net.HttpListenerException: Access is denied

              This one I have no clue about.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups