1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
using System;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using System.Collections.Generic;
namespace CreaturesTactics.Serveur
{
public class CTServeur
{
Thread thread_client = new Thread(new ThreadStart(Start_Serveur));
/// <summary>
/// declaration d un listener permettant d ecoute les ports TCP
/// </summary>
private TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"),2012);
/// <summary>
/// declaration d un client
/// </summary>
private TcpClient client;
/// <summary>
/// declaration d un tableau de byte pour la transmission des données
/// </summary>
private byte[] readBuffer;
private byte[] sendBuffer;
private int i;
private string infoReceived;
private string infoSend;
private Boolean connected;
private CallBack_Reception_Serveur callback;
private CallBack_Reception_Serveur deco;
public delegate void CallBack_Reception_Serveur(out string str);
public CTServeur()
{
listener.Start();
client = listener.AcceptTcpClient;
thread_client.Start
connected = true;
}
public void Start_Serveur()
{
while (true)
{
try
{
string str = System.Text.Encoding.ASCII.GetString(readBuffer, 0, readBuffer.Length);
i = client.GetStream().Read(readBuffer, 0, readBuffer.Length);
callback.BeginInvoke(out str, null, null);
}
catch (Exception e)
{
string str = string.Empty;
deco.BeginInvoke(out str, null, null);
}
}
} |
Partager