J'ai un programme appelé echoclient et un autre appeler echoserveur. Ils sont justes car c'est le professeur qui les a fait et les a compilé (sous linux) . Le probleme c est que je suis sous windows , j ai telecharger et installer Dev C++ et je sais pas comment lancer ces executables. (je sais qu il faut taper "$./echoServer 900 " pour lancer le serveur et $./echoClient <port> <adresse_du_serveur> mais ca c est sous linux et en plus je sais pas ce qu il faut mettre a la place de <adresse_du_serveur>).
mes 2 programmes "echoclients" et "echoserveur" realise la chose suivante, le client envoie une chaine de caractere et le serveur lui renvoie (comme un ecco donc).Pour info voici les programmes:
VOICI ECCHOCLIENT
//
// Socket client using TCP
//
// ---------------------------------------------------------------------
// This function:
// - reads a string from std input (until '\n')
// - writes it to the socket
// - receives the copy through the socket
// - writes it back to the std output
// ---------------------------------------------------------------------
void str_cli(int sockfd)
{
char ws[MAXLEN];
char rs[MAXLEN];
int n_bytes, n_written, n_read;
// read the string to send
cout << "Please enter a string (no spaces)" << endl;
cin >> ws;
n_bytes = strlen(ws)+1;
// write on socket
n_written = write(sockfd, ws, n_bytes);
// see if you missed some characters
if (n_written < n_bytes)
fprintf(stderr, "Client warning: incomplete string sent\n");
// read the answer from the socket
n_read = read(sockfd, rs, MAXLEN);
// see if you lost some more characters on the way back
if (n_read < n_written)
fprintf(stderr, "Client warning: incomplete string received\n");
// writes the received string
cout << "This is the reply that I got back from the other side:" << endl;
cout << rs << endl;
}
// ---------------------------------------------------------------------
// main
// ---------------------------------------------------------------------
main (int argc, char* argv[])
{
int sockfd, clilen;
struct sockaddr_in serv_addr;
// check command line
if (argc < 3) {
cout << "Usage: echoClient <server port number> <server hostname>" << endl;
return(0);
}
// port number is given as first argument
const int serv_port = atoi(argv[1]);
// retrieve host information from name
struct hostent* hptr = gethostbyname(argv[2]);
if (hptr == NULL) {
cout << "echoClient: Error in gethostbyname(), "
<< "please check server host name" << endl;
return(0);
}
// look in address list
char** addrlist = hptr->h_addr_list;
struct in_addr* aptr;
// Fill in the structure with the server address
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
serv_addr.sin_port = htons(serv_port);
// Open a TCP socket
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
fprintf(stderr, "Client: error, cannot open stream socket\n");
return(0);
}
// Connect to the server
if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
fprintf(stderr, "Client: error, cannot connect to server\n");
return(0);
}
// This function:
// - reads a string from a socket
// - writes it back to the same socket
void str_echo(int sockfd)
{
char s[MAXLEN];
int n_written, n_read;
// read the string from socket
n_read = read(sockfd, s, MAXLEN);
// print the received string
cout << "String read: " << s << endl;
// write back
n_written = write(sockfd, s, n_read);
// see if you missed some characters
if (n_written < n_read)
fprintf(stderr, "Server warning: incomplete string sent\n");
}
main (int argc, char* argv[])
{
int sockfd, newsockfd;
socklen_t clilen;
struct sockaddr_in cli_addr, serv_addr;
// server port number
if (argc < 2) {
cout << "Argument: server port number" << endl;
return(0);
}
int serv_port = atoi(argv[1]);
// Open a TCP socket
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
fprintf(stderr, "Error in server: can't open socket\n");
return(0);
}
// bind the local address with specified port number
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(serv_port);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
fprintf(stderr, "Error in server: can't bind local address\n");
return(0);
}
listen(sockfd,1);
for (;;) {
// Wait for connections from clients.
// Iterative server.
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);