K
KFK_Wolf
Guest
TcpListener listener = null;
try
{
ShowServerNetworkConfig();
listener = new TcpListener(IPAddress.Any, 8080);
listener.Start();
new Logger().LogAl("Server Started Port(8080)");
while (true)
{
new Logger().LogAl("Waiting Connection");
TcpClient client = listener.AcceptTcpClient();
new Logger().LogAl("New User Connection");
Thread t = new Thread(ProcessClientRequests);
t.Start(client);
ID = ID + 1;
}
}
catch (Exception exy)
{
new Logger().LogError(exy);
}
finally
{
if (listener != null)
{
listener.Stop();
}
}
Main Void
public int ID = 1;
private void ShowServerNetworkConfig()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
new Logger().LogAl(adapter.Description);
new Logger().LogAl("\tAdapter: " + adapter.Name);
new Logger().LogAl("\tMAC Address: " + adapter.GetPhysicalAddress());
IPInterfaceProperties ip_properties = adapter.GetIPProperties();
UnicastIPAddressInformationCollection addresses = ip_properties.UnicastAddresses;
foreach (UnicastIPAddressInformation address in addresses)
{
new Logger().LogAl("\tIP Address: " + address.Address);
}
}
}
private void ProcessClientRequests(object argument)
{
int botpoint = 0;
int requestCount = 0;
byte[] bytesFrom = new byte[4096 * 2];
string dataFromClient = null;
string serverResponse = null;
requestCount = 0;
int banlanmasayısı = 0;
int clientNo = ID;
int ClientNumber = clientNo;
DateTime banbitis = DateTime.Now.AddDays(-1);
TcpClient client = (TcpClient)argument;
bool Logined = false;
Player Oyuncumuz = new Player();
try
{
StreamReader reader = new StreamReader(client.GetStream());
StreamWriter writer = new StreamWriter(client.GetStream());
string s = String.Empty;
while (!(s = reader.ReadLine()).Equals("SERVERDATABASEPLATFORMSYSTEMEXIT") || (s == null))
{
requestCount = requestCount + 1;
dataFromClient = reader.ReadLine();
new Logger().LogAl("Player " + clientNo + ":" + dataFromClient);
serverResponse = "1";
writer.Write(serverResponse);
writer.Flush();
}
reader.Close();
writer.Close();
new Logger().LogAl("Bağlantı Kapatıldı.");
}
catch (IOException)
{
new Logger().LogAl("Client Connection Error !");
}
finally
{
if (client != null)
{
client.Close();
}
}
public class Logger{
public void LogAl(string Log)
{
Server.Properties.Settings.Default.Log += Log;
}
}
Continue reading...
try
{
ShowServerNetworkConfig();
listener = new TcpListener(IPAddress.Any, 8080);
listener.Start();
new Logger().LogAl("Server Started Port(8080)");
while (true)
{
new Logger().LogAl("Waiting Connection");
TcpClient client = listener.AcceptTcpClient();
new Logger().LogAl("New User Connection");
Thread t = new Thread(ProcessClientRequests);
t.Start(client);
ID = ID + 1;
}
}
catch (Exception exy)
{
new Logger().LogError(exy);
}
finally
{
if (listener != null)
{
listener.Stop();
}
}
Main Void
public int ID = 1;
private void ShowServerNetworkConfig()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
new Logger().LogAl(adapter.Description);
new Logger().LogAl("\tAdapter: " + adapter.Name);
new Logger().LogAl("\tMAC Address: " + adapter.GetPhysicalAddress());
IPInterfaceProperties ip_properties = adapter.GetIPProperties();
UnicastIPAddressInformationCollection addresses = ip_properties.UnicastAddresses;
foreach (UnicastIPAddressInformation address in addresses)
{
new Logger().LogAl("\tIP Address: " + address.Address);
}
}
}
private void ProcessClientRequests(object argument)
{
int botpoint = 0;
int requestCount = 0;
byte[] bytesFrom = new byte[4096 * 2];
string dataFromClient = null;
string serverResponse = null;
requestCount = 0;
int banlanmasayısı = 0;
int clientNo = ID;
int ClientNumber = clientNo;
DateTime banbitis = DateTime.Now.AddDays(-1);
TcpClient client = (TcpClient)argument;
bool Logined = false;
Player Oyuncumuz = new Player();
try
{
StreamReader reader = new StreamReader(client.GetStream());
StreamWriter writer = new StreamWriter(client.GetStream());
string s = String.Empty;
while (!(s = reader.ReadLine()).Equals("SERVERDATABASEPLATFORMSYSTEMEXIT") || (s == null))
{
requestCount = requestCount + 1;
dataFromClient = reader.ReadLine();
new Logger().LogAl("Player " + clientNo + ":" + dataFromClient);
serverResponse = "1";
writer.Write(serverResponse);
writer.Flush();
}
reader.Close();
writer.Close();
new Logger().LogAl("Bağlantı Kapatıldı.");
}
catch (IOException)
{
new Logger().LogAl("Client Connection Error !");
}
finally
{
if (client != null)
{
client.Close();
}
}
public class Logger{
public void LogAl(string Log)
{
Server.Properties.Settings.Default.Log += Log;
}
}
Continue reading...