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

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

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


Revision 1.3 - (show annotations) (download) (as text)
Tue Jan 15 06:11:38 2002 UTC (18 years, 4 months ago) by stdarg
Branch: MAIN
Changes since 1.2: +1 -1 lines
File MIME type: text/x-chdr
* Added client/server option to sslmode.c and got rid of auto-negotation.
* Experimented with preset dictionaries in zipmode.c... not very successful.
* Cleaned up some stuff.

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 static int baa = 0;
18
19 if (!baa) {
20 printf("Connected to server!\n");
21 sslmode_on(idx, 0);
22 zipmode_on(idx);
23 linemode_on(idx);
24 baa++;
25 }
26 return(0);
27 }
28
29 int server_read(int idx, sockbuf_iobuf_t *data, void *client_data)
30 {
31 printf("%s\n", data->data);
32 return(0);
33 }
34
35 int server_eof(sockbuf_t *sbuf, void *client_data)
36 {
37 printf("Server closed connection!\n");
38 exit(0);
39 }
40
41 static sockbuf_event_t server_event = {
42 (Function) 4,
43 (Function) "server",
44 server_read,
45 server_connect,
46 server_eof,
47 server_err
48 };
49
50 int stdin_read(int idx, sockbuf_iobuf_t *data, void *client_data)
51 {
52 data->data[data->len] = '\n';
53 sockbuf_write(server_idx, data->data, data->len+1);
54 return(0);
55 }
56
57
58 int stdin_eof(int idx, void *client_data)
59 {
60 sockbuf_delete(idx);
61 return(0);
62 }
63
64 static sockbuf_event_t stdin_event = {
65 (Function) 4,
66 (Function) "stdin",
67 stdin_read,
68 NULL,
69 stdin_eof,
70 NULL
71 };
72
73 main (int argc, char *argv[])
74 {
75 int sock, port, stdin_idx;
76 char *host;
77
78 srand(time(0));
79 if (argc < 2) {
80 host = "127.0.0.1";
81 port = 12345;
82 }
83 else if (argc == 2) {
84 host = argv[1];
85 port = 12345;
86 }
87 else {
88 host = argv[1];
89 port = atoi(argv[2]);
90 }
91
92 printf("Connecting to %s %d\n", host, port);
93 sock = socket_create(host, port, SOCKET_CLIENT);
94 if (sock < 0) {
95 perror("socket_create");
96 return(0);
97 }
98 socket_set_nonblock(sock, 1);
99 socket_set_nonblock(0, 1);
100 server_idx = sockbuf_new(sock, SOCKBUF_CLIENT);
101 sockbuf_set_handler(server_idx, server_event, NULL);
102 //zipmode_on(server_idx);
103 //linemode_on(server_idx);
104 sslmode_init();
105
106 stdin_idx = sockbuf_new(0, 0);
107 sockbuf_set_handler(stdin_idx, stdin_event, NULL);
108 linemode_on(stdin_idx);
109 while (1) {
110 sockbuf_update_all(-1);
111 }
112 return(0);
113 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23