Bonjour a tous je ne sais pas si je poste sur le bon sujet mais voila j'ai un problème.
Je veu tout simplement créer un server mais je n'y arrive pas.

Le but étant que grace a ma fonction pour utiliser le server il me retourne un bool pour savoir si la focntion c'est correctement efféctué.

Voila les codes:

Code C/C++ :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * serverfunction.h
 *
 *  Created on: 18 mars 2010
 *    
 */
 
#ifndef SERVERFUNCTION_H_
#define SERVERFUNCTION_H_
using namespace std;
class SocketServer
{
public:
	bool InitSocketServer(const char Address, int Port);
};
 
 
#endif /* SERVERFUNCTION_H_ */

Code C/C++ :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
75
76
77
78
/*
 * serverfunction.cpp
 *
 *  Created on: 18 mars 2010
 *      
 */
 
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "serverfunction.h"
using namespace std;
 
 
bool SocketServer::InitSocketServer(const char * Address, int Port)
{
 
	bool CreateSocket = false;
    struct sockaddr_in SocketServerParam;
    int SocketServer;
 
    // Configure a server socket in connected mode...
    SocketServer = socket(AF_INET, SOCK_STREAM, 0) ;
    if (SocketServer != -1)
    {
    	memset(&SocketServerParam, 0, sizeof (struct sockaddr_in)) ;
    	/*Set the first numbyte of the block memory
    	//pointed by ptr to the specified value (ptr, value to be set, number of
    	bytes to be set to the value)*/
    	SocketServerParam.sin_family = AF_INET;
        // ...on specified address and port...
    	SocketServerParam.sin_port = htons(Port) ; //Port
    	SocketServerParam.sin_addr.s_addr = inet_addr(Address) ; //Address IP
        if (SocketServerParam.sin_addr.s_addr != INADDR_NONE)
        {
        	/* bind the socket to the Internet address */
            if (bind(SocketServer, (struct sockaddr *) &SocketServerParam,
                sizeof (struct sockaddr_in)) != -1)
            {
                // Allow IP address immediate reuse
                int flagReuseAddress = 1;
                if (setsockopt(SocketServer, SOL_SOCKET, SO_REUSEADDR,
                    &flagReuseAddress, sizeof (int)) != -1)
                {
                	// ...for one client
					if (listen(SocketServer, 1) != -1)
					{
                	// Initialize DbMa_SdbtpInterfaceFileDescriptor
                	// variable
                	int DbMa_SdbtpInterfaceFileDescriptor = accept(
                			CreateSocket, NULL, NULL) ;
 
						if (DbMa_SdbtpInterfaceFileDescriptor != -1)
						{
							// The connection is established with the client
							CreateSocket = true;
						}
 
                	}
 
                }
 
            }
 
 
        }
        // Close Sdbtp socket connection server
        close(SocketServer) ;
    }
return CreateSocket;
}
Code C/C++ :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
*
 * server.cpp
 *
 *  Created on: 18 mars 2010
 *    
 */
 
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "serverfunction.h"
using namespace std;
int main (void)
 
{
SocketServer sockServ; //Instanter class
sockServ.InitSocketServer("127.0.0.1", 2000)
}
Mon programme est sous l'environnement Linux.
Je vous met ci dessous mes erreurs (je trvail sous eclipse):
prototype for 'bool SocketServer::InitSocketServer(const char*,int)' does not match any in class 'SocketServer'
candidate is: bool SocketServer::InitSocketServer(char, int)
invalid conversion from 'const char*' to 'char'
initialize argument 1 of 'bool SocketServer::InitSocketServer(char, int)