| 1 |
/* |
| 2 |
* SRT - Secure, Reliable, Transport |
| 3 |
* Copyright (c) 2017 Haivision Systems Inc. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; If not, see <http://www.gnu.org/licenses/> |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <stdlib.h> |
| 22 |
#ifdef _WIN32 |
| 23 |
#define usleep(x) Sleep(x / 1000) |
| 24 |
#else |
| 25 |
#include <unistd.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include "srt.h" |
| 29 |
|
| 30 |
int main(int argc, char** argv) |
| 31 |
{ |
| 32 |
int ss, st; |
| 33 |
struct sockaddr_in sa; |
| 34 |
int yes = 1; |
| 35 |
const char message [] = "This message should be sent to the other side"; |
| 36 |
|
| 37 |
if (argc != 3) { |
| 38 |
fprintf(stderr, "Usage: %s <host> <port>\n", argv[0]); |
| 39 |
return 1; |
| 40 |
} |
| 41 |
|
| 42 |
printf("srt startup\n"); |
| 43 |
srt_startup(); |
| 44 |
|
| 45 |
printf("srt socket\n"); |
| 46 |
ss = srt_create_socket(); |
| 47 |
if (ss == SRT_ERROR) |
| 48 |
{ |
| 49 |
fprintf(stderr, "srt_socket: %s\n", srt_getlasterror_str()); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
printf("srt remote address\n"); |
| 54 |
sa.sin_family = AF_INET; |
| 55 |
sa.sin_port = htons(atoi(argv[2])); |
| 56 |
if (inet_pton(AF_INET, argv[1], &sa.sin_addr) != 1) |
| 57 |
{ |
| 58 |
return 1; |
| 59 |
} |
| 60 |
|
| 61 |
printf("srt setsockflag\n"); |
| 62 |
if (SRT_ERROR == srt_setsockflag(ss, SRTO_SENDER, &yes, sizeof yes)) |
| 63 |
{ |
| 64 |
fprintf(stderr, "srt_setsockflag: %s\n", srt_getlasterror_str()); |
| 65 |
return 1; |
| 66 |
} |
| 67 |
|
| 68 |
// Test deprecated |
| 69 |
//srt_setsockflag(ss, SRTO_STRICTENC, &yes, sizeof yes); |
| 70 |
|
| 71 |
printf("srt connect\n"); |
| 72 |
st = srt_connect(ss, (struct sockaddr*)&sa, sizeof sa); |
| 73 |
if (st == SRT_ERROR) |
| 74 |
{ |
| 75 |
fprintf(stderr, "srt_connect: %s\n", srt_getlasterror_str()); |
| 76 |
return 1; |
| 77 |
} |
| 78 |
|
| 79 |
int i; |
| 80 |
for (i = 0; i < 100; i++) |
| 81 |
{ |
| 82 |
printf("srt sendmsg2 #%d >> %s\n",i,message); |
| 83 |
st = srt_sendmsg2(ss, message, sizeof message, NULL); |
| 84 |
if (st == SRT_ERROR) |
| 85 |
{ |
| 86 |
fprintf(stderr, "srt_sendmsg: %s\n", srt_getlasterror_str()); |
| 87 |
return 1; |
| 88 |
} |
| 89 |
|
| 90 |
usleep(1000); // 1 ms |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
sleep(1); // 1 second to give it enough time to receive all messages |
| 95 |
printf("srt close\n"); |
| 96 |
st = srt_close(ss); |
| 97 |
if (st == SRT_ERROR) |
| 98 |
{ |
| 99 |
fprintf(stderr, "srt_close: %s\n", srt_getlasterror_str()); |
| 100 |
return 1; |
| 101 |
} |
| 102 |
|
| 103 |
printf("srt cleanup\n"); |
| 104 |
srt_cleanup(); |
| 105 |
return 0; |
| 106 |
} |