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 #include <unistd.h>
18
19 #include "client_trans_udp_stream_interface.h"
20 #include "session.h"
21
22 #define CHANNELID 1
23 #define CHANNELID2 2
24 #define PKGNAME "test"
25 #define LONG_SLEEP 600
26 #define SESSION_KEY_LENGTH 32
27 #define STREAM_DATA_LENGTH 10
28
SetStatus(int channelId,int status)29 void SetStatus(int channelId, int status)
30 {
31 printf("[server]:channelID:%d, status:%d\n", channelId, status);
32 }
33
OnStreamReceived(int channelId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * param)34 void OnStreamReceived(int channelId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param)
35 {
36 printf("[server]:OnStreamReceived, len:%d, extLen:%d\n", data->bufLen, data->bufLen);
37 printf("[server]:channelID:%d, streamBuf:%.*s\n", channelId, data->bufLen, data->buf);
38
39 StreamData tmpData = {
40 "peipeipei\0",
41 STREAM_DATA_LENGTH,
42 };
43 StreamFrameInfo tmpf = {};
44 int ret = SendVtpStream(channelId, &tmpData, NULL, &tmpf);
45 printf("[server]:DstreamSendStream ret:%d\n", ret);
46 }
47
48 static IStreamListener g_callback = {
49 .OnStatusChange = SetStatus,
50 .OnStreamReceived = OnStreamReceived,
51 };
52
main()53 int main()
54 {
55 int ret;
56
57 VtpStreamOpenParam p1 = {
58 PKGNAME,
59 "127.0.0.1",
60 NULL,
61 -1,
62 RAW_STREAM,
63 (uint8_t*)"abcdef@ghabcdefghabcdefghfgdabc",
64 SESSION_KEY_LENGTH,
65 };
66
67 VtpStreamOpenParam p2 = {
68 PKGNAME,
69 "127.0.0.1",
70 NULL,
71 -1,
72 RAW_STREAM,
73 (uint8_t*)"abcdef\0ghabcdefghabcdefghfgdabc",
74 SESSION_KEY_LENGTH,
75 };
76
77 ret = StartVtpStreamChannelServer(CHANNELID, &p1, &g_callback);
78 printf("[server]:StartChannelServer ret:%d\n", ret);
79
80 ret = StartVtpStreamChannelServer(CHANNELID2, &p2, &g_callback);
81 printf("[server]:StartChannelServer2 ret:%d\n", ret);
82
83 while (1) {
84 printf("[server]:server is running.\n");
85 sleep(LONG_SLEEP);
86 }
87
88 CloseVtpStreamChannel(CHANNELID, PKGNAME);
89 CloseVtpStreamChannel(CHANNELID2, PKGNAME);
90
91 return 0;
92 }
93