~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/websockets_bi_side.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <errno.h>
 
2
#include <sys/types.h>
 
3
#include <sys/socket.h>
 
4
#include <netinet/in.h>
 
5
#include <arpa/inet.h>
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include <string.h>
 
9
#include <unistd.h>
 
10
#include <sys/ioctl.h>
 
11
#if EMSCRIPTEN
 
12
#include <emscripten.h>
 
13
#endif
 
14
 
 
15
#define EXPECTED_BYTES 5
 
16
 
 
17
int main(void)
 
18
{
 
19
  struct sockaddr_in stSockAddr;
 
20
  int Res;
 
21
#if !TEST_DGRAM
 
22
  int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
23
#else
 
24
  int SocketFD = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
25
#endif
 
26
 
 
27
  if (-1 == SocketFD)
 
28
  {
 
29
    perror("cannot create socket");
 
30
    exit(EXIT_FAILURE);
 
31
  }
 
32
 
 
33
  memset(&stSockAddr, 0, sizeof(stSockAddr));
 
34
 
 
35
  stSockAddr.sin_family = AF_INET;
 
36
  stSockAddr.sin_port = htons(SOCKK);
 
37
  Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr);
 
38
 
 
39
  if (0 > Res) {
 
40
    perror("error: first parameter is not a valid address family");
 
41
    close(SocketFD);
 
42
    exit(EXIT_FAILURE);
 
43
  } else if (0 == Res) {
 
44
    perror("char string (second parameter does not contain valid ipaddress)");
 
45
    close(SocketFD);
 
46
    exit(EXIT_FAILURE);
 
47
  }
 
48
 
 
49
  printf("connect..\n");
 
50
 
 
51
  if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) {
 
52
    perror("connect failed");
 
53
    close(SocketFD);
 
54
    exit(EXIT_FAILURE);
 
55
  }
 
56
 
 
57
  printf("send..\n");
 
58
 
 
59
  char data[] = "hello from the other siide\n";
 
60
  send(SocketFD, data, sizeof(data), 0);
 
61
 
 
62
  printf("stall..\n");
 
63
 
 
64
  //int bytes;
 
65
  //while (1) ioctl(SocketFD, FIONREAD, &bytes);
 
66
 
 
67
  return EXIT_SUCCESS;
 
68
}
 
69