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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Getting a console server to do more then connect

Getting a console server to do more then connect

Scheduled Pinned Locked Moved C#
sysadminhelp
7 Posts 2 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.
  • B Offline
    B Offline
    bigjoe11a
    wrote on last edited by
    #1

    What II have is a small server that I been playing a round with. It's just that I can connect to it and that's about it. I been trying to do is get it so I can log and go to a menu and well doesn't look like I can get my answer from some of the other places. So I thought I would try here. Can some one please help me set this up. the code is below. static void Main(string[] args) { int recv; byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 1605); Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); newsock.Bind(ipep); newsock.Listen(10); Console.WriteLine("Waiting for a client..."); Socket client = newsock.Accept(); IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint; Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port); string welcome = "Welcome to my TCP server (© 2008)"; data = Encoding.ASCII.GetBytes(welcome); client.Send(data, data.Length, SocketFlags.None); do { string menu = "L)ogin Q)uit V)iew Log"; data = Encoding.ASCII.GetBytes(menu); client.Send(data, data.Length, SocketFlags.None); string choice = "Command : "; data = Encoding.ASCII.GetBytes(choice); client.Send(data, data.Length, SocketFlags.None); switch (choice.ToUpper()) { case "Q": break; case "L": Login(); break; case "V": break; default: string NotThere = "Wrong Choice"; data = Encoding.ASCII.GetBytes(NotThere); client.Send(data, data.Length, SocketFlags.None); break; } } while (choice != "Q"); while (true) { data = new byte[1024]; recv = client.Receive(data); if (recv == 0) break; Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv)); client.Send(data, recv, SocketFlags.None); } Con

    S 1 Reply Last reply
    0
    • B bigjoe11a

      What II have is a small server that I been playing a round with. It's just that I can connect to it and that's about it. I been trying to do is get it so I can log and go to a menu and well doesn't look like I can get my answer from some of the other places. So I thought I would try here. Can some one please help me set this up. the code is below. static void Main(string[] args) { int recv; byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 1605); Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); newsock.Bind(ipep); newsock.Listen(10); Console.WriteLine("Waiting for a client..."); Socket client = newsock.Accept(); IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint; Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port); string welcome = "Welcome to my TCP server (© 2008)"; data = Encoding.ASCII.GetBytes(welcome); client.Send(data, data.Length, SocketFlags.None); do { string menu = "L)ogin Q)uit V)iew Log"; data = Encoding.ASCII.GetBytes(menu); client.Send(data, data.Length, SocketFlags.None); string choice = "Command : "; data = Encoding.ASCII.GetBytes(choice); client.Send(data, data.Length, SocketFlags.None); switch (choice.ToUpper()) { case "Q": break; case "L": Login(); break; case "V": break; default: string NotThere = "Wrong Choice"; data = Encoding.ASCII.GetBytes(NotThere); client.Send(data, data.Length, SocketFlags.None); break; } } while (choice != "Q"); while (true) { data = new byte[1024]; recv = client.Receive(data); if (recv == 0) break; Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv)); client.Send(data, recv, SocketFlags.None); } Con

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      bigjoe11a wrote:

      I been trying to do is get it so I can log and go to a menu

      Would you please rephrase this, what are you trying to do?

      B 1 Reply Last reply
      0
      • S ScottM1

        bigjoe11a wrote:

        I been trying to do is get it so I can log and go to a menu

        Would you please rephrase this, what are you trying to do?

        B Offline
        B Offline
        bigjoe11a
        wrote on last edited by
        #3

        What I want to do. Is log in and have a menu with choices. The only thing I could do with this server is connect and thats it. I wanted en option that when I connected to the server. I could log in and it would take me to a menu. Then I could do some thing or log off. Sorry I been up late nights so my typing may not be all that great. Joe

        S 1 Reply Last reply
        0
        • B bigjoe11a

          What I want to do. Is log in and have a menu with choices. The only thing I could do with this server is connect and thats it. I wanted en option that when I connected to the server. I could log in and it would take me to a menu. Then I could do some thing or log off. Sorry I been up late nights so my typing may not be all that great. Joe

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          Your menu would have to be on your client and then your client would forward the command to your server.

          B 1 Reply Last reply
          0
          • S ScottM1

            Your menu would have to be on your client and then your client would forward the command to your server.

            B Offline
            B Offline
            bigjoe11a
            wrote on last edited by
            #5

            Ok, so would you need my client source code to show me how to do that or what do you need.

            S 1 Reply Last reply
            0
            • B bigjoe11a

              Ok, so would you need my client source code to show me how to do that or what do you need.

              S Offline
              S Offline
              ScottM1
              wrote on last edited by
              #6

              No, I've already told you what to do. Try it and let me know where you have problems.

              B 1 Reply Last reply
              0
              • S ScottM1

                No, I've already told you what to do. Try it and let me know where you have problems.

                B Offline
                B Offline
                bigjoe11a
                wrote on last edited by
                #7

                LOL. Right. If I new how to do that I wouldn't have posted a message asking for help.

                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