| 1 |
/* |
| 2 |
* SRT - Secure, Reliable, Transport |
| 3 |
* Copyright (c) 2018 Haivision Systems Inc. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
|
| 14 |
#include "srt.h" |
| 15 |
|
| 16 |
int main( int argc, char** argv ) |
| 17 |
{ |
| 18 |
if (argc < 3) |
| 19 |
{ |
| 20 |
fprintf(stderr, "Usage: %s <remote host> <remote port>\n", argv[0]); |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
int ss, st; |
| 25 |
struct sockaddr_in sa; |
| 26 |
int yes = 1; |
| 27 |
const char message [] = "This message should be sent to the other side"; |
| 28 |
|
| 29 |
srt_startup(); |
| 30 |
|
| 31 |
ss = srt_create_socket(); |
| 32 |
if ( ss == SRT_ERROR ) |
| 33 |
{ |
| 34 |
fprintf(stderr, "srt_socket: %s\n", srt_getlasterror_str()); |
| 35 |
return 1; |
| 36 |
} |
| 37 |
|
| 38 |
sa.sin_port = htons(atoi(argv[2])); |
| 39 |
if ( inet_pton(AF_INET, argv[1], &sa.sin_addr) != 1) |
| 40 |
{ |
| 41 |
return 1; |
| 42 |
} |
| 43 |
|
| 44 |
// This is obligatory only in live mode, if you predict to connect |
| 45 |
// to a peer with SRT version 1.2.0 or older. Not required since |
| 46 |
// 1.3.0, and all older versions support only live mode. |
| 47 |
//srt_setsockflag(ss, SRTO_SENDER, &yes, sizeof yes); |
| 48 |
// |
| 49 |
// In order to make sure that the client supports non-live message |
| 50 |
// mode, let's require this. |
| 51 |
int minversion = SRT_VERSION_FEAT_HSv5; |
| 52 |
srt_setsockflag(ss, SRTO_MINVERSION, &minversion, sizeof minversion); |
| 53 |
|
| 54 |
// Require also non-live message mode. |
| 55 |
int file_mode = SRTT_FILE; |
| 56 |
srt_setsockflag(ss, SRTO_TRANSTYPE, &file_mode, sizeof file_mode); |
| 57 |
srt_setsockflag(ss, SRTO_MESSAGEAPI, &yes, sizeof yes); |
| 58 |
|
| 59 |
// Note that the other side will reject the connection if the |
| 60 |
// listener didn't set the same mode. |
| 61 |
|
| 62 |
st = srt_connect(ss, (struct sockaddr*)&sa, sizeof sa); |
| 63 |
if ( st == SRT_ERROR ) |
| 64 |
{ |
| 65 |
fprintf(stderr, "srt_connect: %s\n", srt_getlasterror_str()); |
| 66 |
return 1; |
| 67 |
} |
| 68 |
|
| 69 |
st = srt_send(ss, message, sizeof message); |
| 70 |
if ( st == SRT_ERROR ) |
| 71 |
{ |
| 72 |
fprintf(stderr, "srt_sendmsg: %s\n", srt_getlasterror_str()); |
| 73 |
return 1; |
| 74 |
} |
| 75 |
|
| 76 |
st = srt_close(ss); |
| 77 |
if ( st == SRT_ERROR ) |
| 78 |
{ |
| 79 |
fprintf(stderr, "srt_close: %s\n", srt_getlasterror_str()); |
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
srt_cleanup(); |
| 84 |
return 0; |
| 85 |
} |