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
| private string sResultat = "";
public string ConnectRxCP(string sNomServeur, int iPortServeur, string LmsID, string UnitId, int iPortReception)
{
// Construction de la chaine d'initialisation
StringBuilder str = new StringBuilder();
str.Append("tcp://" + Environment.GetEnvironmentVariable("COMPUTERNAME") + "." + Environment.GetEnvironmentVariable("USERDNSDOMAIN") + ":" + iPortReception.ToString() + "/");
// Connexion au serveur RxCP
socketClient = new TcpClient();
socketClient.Connect(sNomServeur, iPortServeur);
// Demande d'Intialisation
byte[] abInit = Encoding.Unicode.GetBytes(str.ToString());
socketClient.GetStream().Write(abInit, 0, abInit.Length);
// Ecoute de la réponse du serveur RxCP
iPortReceptionServeur = iPortReception;
MainLoop();
return sResultat;
}
private void MainLoop()
{
TcpListener listener = new TcpListener(IPAddress.Any, iPortReceptionServeur);
listener.Start(1);
try
{
bool Stopped = false;
while (!Stopped)
{
if (listener.Pending())
{
// Le programme ne rentre pas dans la boucle. Pourquoi?
sResultat = "connexion RxCP recue";
Stopped = true;
}
else
Stopped = true;
}
}
finally
{
listener.Stop();
}
} |
Partager