source: trunk/instant_messenger/socket/BKP_20071105/BKP_20071026/BKP_20071019/BKP_20071018/BKP_20071009/BKP_20071008/BKP/BKP/client2.c @ 151

Revision 151, 1.3 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <netinet/in.h>
8
9#include <unistd.h>
10#include <fcntl.h>
11
12int main()
13{
14  register int s;
15  register int bytes;
16  struct sockaddr_in sa;
17  //char buffer[BUFSIZ+1];
18  int status = 1;
19  char * buffer = malloc(BUFSIZ),//(char)NULL;
20                 * xml_connect = {"<?xml version='1.0' encoding='UTF-8'?><stream:stream to='localhost' xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"};
21 
22  //fcntl(O_NONBLOCK, F_SETFL, 0);
23  //fcntl(O_ASYNC, F_SETFL, 1);
24  if ( (s = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
25  {
26    perror("socket");
27    return 1;
28  }
29
30  bzero(&sa, sizeof sa);
31
32  sa.sin_family = AF_INET;
33  sa.sin_port = htons(5222);
34  sa.sin_addr.s_addr = htonl((((((127 << 8) | 0) << 8) | 0) << 8) | 1);
35
36  //fcntl(O_NONBLOCK, F_SETFL, 0);
37  //fcntl(O_ASYNC, F_SETFL, 1);
38  if ( connect(s, (struct sockaddr *)&sa, sizeof sa) < 0 )
39  {
40    perror("connect");
41    close(s);
42    return 2;
43  }
44 
45  printf("::: %d\n\n\n", fcntl( s, F_SETFL, fcntl( s, F_GETFL ) & ~O_NONBLOCK ));
46
47  write(s, xml_connect, sizeof(xml_connect)-1);
48
49  while ((bytes = read(s, buffer, 4096)) > 0)
50  //bytes = read(s, buffer, 1);//BUFSIZ);
51  printf("%s", buffer);
52
53  close(s);
54  return 0;
55}
Note: See TracBrowser for help on using the repository browser.