Bonjours a tous,
J'ai une page Asp.Net qui doit ce connecter a un server en C++ or j'ai un message d'erreur
Code :
{"Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée 127.0.0.1:7000"}
Mon serveur C++ marche très bien car j'ai crée un Client C++ , mon client se connecte j'arrive a envoyer et recevoir.
Mon Client Asp.net marche très bien car j'ai crée un serveur en C# et en C++.Net , mon client se connecte j'arrive a envoyer et recevoir.
voic des exemples de code:
Client Asp.net
Code ASP.NET :
public void LauncherClient()
{
// Parse L'adresse IP a partir du textbox avec objet IPAddress
ipAddr = IPAddress.Parse(TextBoxIP.Text);
ipPort = Convert.ToInt32(TextBoxPort.Text);
// Demarre une nouvelle connection TCP vers le server
Client = new TcpClient();
Socket s;
IPEndPoint hostEndPoint = new IPEndPoint(ipAddr, ipPort);
try
{
Client.Connect(hostEndPoint);
}
catch (SocketException e)
{
TextBoxPort.Text = e.Message;
}
// Change le nom du button
ButtonConnecte.Enabled = false ;
// Demarre le Thread pour recevoir les trames
thrMessaging = new Thread(new ThreadStart(ReceiveMessages));
thrMessaging.Start();
}
Client C++
Code C/C++ :
Client::Client(char* _ip, int _port){
// Initialisation de Winsock
erreur=WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if (erreur!=0)
printf("Desole, je ne peux pas initialiser Winsock du a l'erreur : %d %d\n",erreur,WSAGetLastError());
else
printf("WSAStartup : OK\n");
// Ouverture d'une Socket
id_de_la_socket=socket(AF_INET,SOCK_STREAM,0);
if (id_de_la_socket==INVALID_SOCKET)
printf("Desole, je ne peux pas creer la socket du a l'erreur : %d\n",WSAGetLastError());
else
printf("socket : OK\n");
IP = new char[strlen(_ip)+1];
strcpy(IP,_ip);
PORT = _port;
}
void Client::Connecter(){
// Ouverture de la session TCP sur destination de l'adresse IP et du port
information_sur_la_destination.sin_family=AF_INET;
information_sur_la_destination.sin_addr.s_addr=inet_addr(IP); // Indiquez l'adresse IP de votre serveur
information_sur_la_destination.sin_port=PORT; // Port écouté du serveur (33333)
erreur=connect(id_de_la_socket,(struct sockaddr*)&information_sur_la_destination,sizeof(information_sur_la_destination));
if (erreur!=0)
printf("Desole, je n'ai pas pu ouvrir la session TCP : %d %d\n",erreur,WSAGetLastError());
else
printf("setsockopt : OK\n");
}
Server C#
Code C# :
public void StartListening()
{
// Get the IP of the first network device, however this can prove unreliable on certain configurations
IPAddress ipaLocal = ipAddress;
// Create the TCP listener object using the IP of the server and the specified port
tlsClient = new TcpListener(7000);
// Start the TCP listener and listen for connections
tlsClient.Start();
// The while loop will check for true in this before checking for connections
ServRunning = true;
// Start the new tread that hosts the listener
thrListener = new Thread(KeepListening);
thrListener.Start();
}
Server C++
Code C/C++ :
Serveur::Serveur(void)
{
//dit à l'ordinateur que nous allons utiliser des sockets
WSAStartup(MAKEWORD(2,0), &WSAData);
// Initialise les parametre du serveur
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
//sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_family = AF_INET;
sin.sin_port = 7000;
sock = socket(AF_INET,SOCK_STREAM,0);
//attache notre socket directement au port et à l'adresse définis dans la struct SOCKADDR_IN
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
//écoute le port de le socket
listen(sock,0);
}
Sa serais vraiment bien si vous pouviez m'aider sa fait environ ma deuxième semaines que je suis sur ce problème.
Merci d'avance.