diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-01 16:35:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-01 16:35:27 -0700 |
commit | 6c8ac389060b685dec87faade39841c2799c4d0a (patch) | |
tree | 497941020c5863a2a0052ad1088b47c2b0b39424 /tests/websockets_bi_side.c | |
parent | 2a4599a92a570a461a60b1eb79df03908a047711 (diff) |
add socket send(), and almost working test
Diffstat (limited to 'tests/websockets_bi_side.c')
-rw-r--r-- | tests/websockets_bi_side.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/websockets_bi_side.c b/tests/websockets_bi_side.c new file mode 100644 index 00000000..52a2c40e --- /dev/null +++ b/tests/websockets_bi_side.c @@ -0,0 +1,56 @@ +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <emscripten.h> + +#define EXPECTED_BYTES 5 + +int main(void) +{ +emscripten_run_script("console.log('hallo from siide')"); + printf("hello from side page\n"); + + struct sockaddr_in stSockAddr; + int Res; + int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (-1 == SocketFD) + { + perror("cannot create socket"); + exit(EXIT_FAILURE); + } + + memset(&stSockAddr, 0, sizeof(stSockAddr)); + + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(8996); + Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr); + + if (0 > Res) { + perror("error: first parameter is not a valid address family"); + close(SocketFD); + exit(EXIT_FAILURE); + } else if (0 == Res) { + perror("char string (second parameter does not contain valid ipaddress)"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { + perror("connect failed"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + char data[] = "hello from the other siide\n"; + send(SocketFD, data, sizeof(data), 0); + + return EXIT_SUCCESS; +} + |