tcp_socket_clie.c
1.32 KB
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
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <scot/socket.h>
#include <scot/socket_in.h>
#include <scot/stream.h>
#include <scot/exception.h>
#include <scot_common.h>
int
main (int argc, char * argv [])
{
excenv_t * ee;
struct scot_socket * sock;
char puffer [1024];
struct scot_stream * sock_stream;
scot_socket_init (2,2);
atexit (exc_end);
atexit (scot_socket_fini);
TRY
{
sock = scot_socket_in_new ("tcp", "7777");
/*scot_socket_connect (sock, "10.2.5.50");*/
scot_socket_connect (sock, "localhost");
sock_stream = (struct scot_stream *) sock;
printf ("Client: "); fflush (stdout);
while (fgets (puffer, 1024, stdin) != NULL)
{
if (send (sock_stream->handle.sock, puffer, strlen (puffer), 0) !=
strlen (puffer))
THROW (EXC (EXC_ERROR, errno, "Client: Fehler beim schreiben."));
if (strlen (puffer) == 2 && puffer [0] == 'q')
break;
printf ("Client: "); fflush (stdout);
}
scot_socket_free (sock);
}
CATCH (ee)
{
exception_t *e;
while (e = retrive_exception (ee))
{
switch (exc_errnum_get (e))
{
case SCOT_SOCKET_CONNECT_FAIL:
scot_socket_free (sock);
case SCOT_SOCKET_NEW_FAIL:
break;
}
print_exception (e);
free_exception (e);
}
free_catched (ee);
}
return 0;
}