/[cvs]/eggdrop1.9/testcode/client.c
ViewVC logotype

Annotation of /eggdrop1.9/testcode/client.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download) (as text)
Tue Jan 8 00:09:09 2002 UTC (18 years, 5 months ago) by stdarg
Branch: MAIN
File MIME type: text/x-chdr
Err, I don't know if I already added these files or not, so I'll add them again.

1 stdarg 1.1 #include <stdio.h>
2     #include <stdlib.h>
3    
4     #include "my_socket.h"
5     #include "sockbuf.h"
6    
7     int server_idx;
8    
9     int server_err(int idx, int err, void *client_data)
10     {
11     perror("server_err");
12     exit(0);
13     }
14    
15     int server_connect(int idx, void *client_data)
16     {
17     printf("Connected to server!\n");
18     return(0);
19     }
20    
21     int server_read(int idx, sockbuf_iobuf_t *data, void *client_data)
22     {
23     printf("%s\n", data->data);
24     return(0);
25     }
26    
27     int server_eof(sockbuf_t *sbuf, void *client_data)
28     {
29     printf("Server closed connection!\n");
30     exit(0);
31     }
32    
33     static sockbuf_event_t server_event = {
34     (Function) 4,
35     (Function) "server",
36     server_read,
37     server_connect,
38     server_eof,
39     server_err
40     };
41    
42     int stdin_read(int idx, sockbuf_iobuf_t *data, void *client_data)
43     {
44     data->data[data->len] = '\n';
45     sockbuf_write(server_idx, data->data, data->len+1);
46     return(0);
47     }
48    
49    
50     int stdin_eof(int idx, void *client_data)
51     {
52     exit(0);
53     }
54    
55     static sockbuf_event_t stdin_event = {
56     (Function) 4,
57     (Function) "stdin",
58     stdin_read,
59     NULL,
60     stdin_eof,
61     NULL
62     };
63    
64     main (int argc, char *argv[])
65     {
66     int sock, port, stdin_idx;
67    
68     if (argc < 2) {
69     printf("syntax: %s <server> [port]\n", argv[0]);
70     return(0);
71     }
72     if (argc < 3) port = 7000;
73     else port = atoi(argv[2]);
74    
75     sock = socket_create(argv[1], port, SOCKET_CLIENT);
76     if (sock < 0) {
77     perror("socket_create");
78     return(0);
79     }
80     socket_set_nonblock(sock, 1);
81     socket_set_nonblock(0, 1);
82     server_idx = sockbuf_new(sock, SOCKBUF_CLIENT);
83     sockbuf_set_handler(server_idx, server_event, NULL);
84     zipmode_on(server_idx);
85     linemode_on(server_idx);
86    
87     stdin_idx = sockbuf_new(0, 0);
88     sockbuf_set_handler(stdin_idx, stdin_event, NULL);
89     linemode_on(stdin_idx);
90     while (1) {
91     sockbuf_update_all(-1);
92     }
93     return(0);
94     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23