Getting a console server to do more then connect
-
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
-
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
-
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?
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
-
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
-
Your menu would have to be on your client and then your client would forward the command to your server.
-
Ok, so would you need my client source code to show me how to do that or what do you need.