1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17
18 #include "client_trans_udp_stream_interface.h"
19 #include "session.h"
20
21 #define CHANNELID 1
22 #define CHANNELID2 2
23 #define PKGNAME "test"
24 #define TWO_CLIENT_ARGC 3
25 #define FIRST_ARGV 1
26 #define SECOND_ARGV 2
27 #define SHORT_SLEEP 3
28 #define LONG_SLEEP 30
29 #define LOOP_ROUND 10
30
31
SetStatus(int channelId,int status)32 void SetStatus(int channelId, int status)
33 {
34 printf("[client]:channelID:%d, status:%d\n", channelId, status);
35 }
36
OnStreamReceived(int channelId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * param)37 void OnStreamReceived(int channelId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param)
38 {
39 printf("[client]:OnStreamReceived, len:%d, extLen:%d", data->bufLen, ext->bufLen);
40 printf("[client]:channelID:%d, streamBuf:%.*s\n", channelId, data->bufLen, data->buf);
41 }
42
43 static IStreamListener g_callback = {
44 .OnStatusChange = SetStatus,
45 .OnStreamReceived = OnStreamReceived,
46 };
47
main(int argc,char * argv[])48 int main(int argc, char *argv[])
49 {
50 if (argc != TWO_CLIENT_ARGC) {
51 printf("[client]:Please input server sorcket to connect\n");
52 return 0;
53 }
54 int port = atoi(argv[FIRST_ARGV]);
55 int port2 = atoi(argv[SECOND_ARGV]);
56 int ret;
57
58 VtpStreamOpenParam p1 = {
59 PKGNAME,
60 "127.0.0.1",
61 "127.0.0.1",
62 port,
63 RAW_STREAM,
64 "abcdefghabcdefghabcdefghabcdefgh",
65 };
66
67 VtpStreamOpenParam p2 = {
68 PKGNAME,
69 "127.0.0.1",
70 "127.0.0.1",
71 port2,
72 RAW_STREAM,
73 "abcdefghabcdefghabcdefghabcdefgh",
74 };
75
76 ret = StartVtpStreamChannelClient(CHANNELID, &p1, &g_callback);
77 printf("[client]:StartChannelClient ret:%d\n", ret);
78
79 ret = StartVtpStreamChannelClient(CHANNELID2, &p2, &g_callback);
80 printf("[client]:StartChannelClient ret:%d\n", ret);
81
82 sleep(SHORT_SLEEP);
83
84 StreamData tmpData = {
85 "diudiudiu\0",
86 10,
87 };
88
89 StreamData tmpData2 = {
90 "oohoohooh\0",
91 10,
92 };
93 StreamFrameInfo tmpf = {};
94
95 for (int i = 0; i < LOOP_ROUND; i++) {
96 ret = SendVtpStream(CHANNELID, &tmpData, NULL, &tmpf);
97 printf("[client]:DstreamSendStream1 ret:%d\n", ret);
98 ret = SendVtpStream(CHANNELID2, &tmpData2, NULL, &tmpf);
99 printf("[client]:DstreamSendStream2 ret:%d\n", ret);
100 sleep(LONG_SLEEP);
101 }
102
103 CloseVtpStreamChannel(CHANNELID, PKGNAME);
104 CloseVtpStreamChannel(CHANNELID2, PKGNAME);
105 sleep(LONG_SLEEP);
106
107 return 0;
108 }
109