- Joined
- Dec 26, 2006
- Messages
- 1,318
- Reaction score
- 171
ok im new to c# and tried some tuturials around and readed some ebooks about the general stuff of c#.
I made this from some online tuturial:
Im pretty sure i did some horrible stuff in this code,
could somebody optimize this and add comments of like why and how things are being used.
Thanks
I made this from some online tuturial:
PHP:
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class serv {
public static void Main() {
try {
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
TcpListener myList=new TcpListener(ipAd,912);
int lol = 0;
for (int l = 0; l == l; )
{
myList.Start();
if (lol == 0)
{
Console.WriteLine("The server is running...");
Console.WriteLine("The local End point is :" + myList.LocalEndpoint);
lol = 1;
}
Console.WriteLine("");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
char cc = Convert.ToChar(b[0]);
string gg = Convert.ToString(cc);
switch (gg)
{
case "U":
//stuff
break;
default:
Console.WriteLine("Unknown data received: \"" + gg + "\".");
break;
}
Console.WriteLine("Disconnected " + s.RemoteEndPoint);
s.Close();
myList.Stop();
}
}
catch (Exception e) {
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
Im pretty sure i did some horrible stuff in this code,
could somebody optimize this and add comments of like why and how things are being used.
Thanks

