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
|
#ifndef _IVYSOCKET_H
#define _IVYSOCKET_H
#ifdef __cplusplus
extern "C" {
#endif
/* general Handle */
#define ANYPORT 0
#ifdef WIN32
#include <windows.h>
#define HANDLE SOCKET
#else
#define HANDLE int
#include <netinet/in.h>
#endif
/* Server Part */
typedef struct _client *Client;
typedef void (*SocketInterpretation)( Client client, void *data, char *ligne);
extern void SocketInit();
extern void SocketClose( Client client );
extern void SocketSend( Client client, char *fmt, ... );
extern void SocketSendRaw( Client client, char *buffer, int len );
extern char *SocketGetPeerHost( Client client );
extern void SocketSetData( Client client, void *data );
extern void *SocketGetData( Client client );
extern void SocketBroadcast( char *fmt, ... );
extern int SocketServer(unsigned short port,
void*(*create)(Client client),
void(*handle_delete)(Client client, void *data),
SocketInterpretation interpretation);
/* Client Part */
extern Client SocketConnect( char * host, unsigned short port,
void *data,
SocketInterpretation interpretation,
void (*handle_delete)(Client client, void *data)
);
extern Client SocketConnectAddr( struct in_addr * addr, unsigned short port,
void *data,
SocketInterpretation interpretation,
void (*handle_delete)(Client client, void *data)
);
extern int SocketWaitForReply( Client client, char *buffer, int size, int delai);
/* Socket UDP */
/* Creation d'une socket en mode non connecte */
/* et ecoute des messages */
extern Client SocketBroadcastCreate(
unsigned short port,
void *data,
SocketInterpretation interpretation
);
/* recuperation de l'emetteur du message */
extern struct in_addr * SocketGetRemoteAddr( Client client );
extern void SocketGetRemote( Client client, char **host, unsigned short *port );
/* emmission d'un broadcast UDP */
extern void SocketSendBroadcast( Client client, unsigned long host, unsigned short port, char *fmt, ... );
#ifdef __cplusplus
}
#endif
#endif
|