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
79
80
81
82
83
84
85
86
87
88
|
#ifndef _SOCKET_H
#define _SOCKET_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
typedef struct _channel *Channel;
extern void ChannelInit(void);
extern void ChannelStop(void);
extern void ChannelMainLoop(void(*hook)(void) );
extern Channel ChannelSetUp(
HANDLE fd,
void *data,
void (*handle_delete)( void *data ),
void (*handle_read)( Channel channel, HANDLE fd, void *data)
);
extern void ChannelClose( Channel channel );
/* Server Part */
typedef struct _client *Client;
typedef void (*SocketInterpretation)( Client client, void *data, char *ligne);
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 XTMAINLOOP
#include <X11/Intrinsic.h>
extern void SetSocketAppContext( XtAppContext cntx );
#endif
#ifdef __cplusplus
}
#endif
#endif
|