Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
云逸之
SimpleVideoServer
提交
82d15652
S
SimpleVideoServer
项目概览
云逸之
/
SimpleVideoServer
通知
685
Star
47
Fork
14
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SimpleVideoServer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
82d15652
编写于
8月 06, 2022
作者:
云逸之
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充提交udp-simple
上级
7bea7aa8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
0 deletion
+87
-0
simpleVideoRecorder/src/UdpClient.cpp
simpleVideoRecorder/src/UdpClient.cpp
+69
-0
simpleVideoRecorder/src/UdpClient.hpp
simpleVideoRecorder/src/UdpClient.hpp
+18
-0
未找到文件。
simpleVideoRecorder/src/UdpClient.cpp
0 → 100644
浏览文件 @
82d15652
#include "UdpClient.hpp"
#include <Arduino.h>
#include <errno.h>
#include <lwip/netdb.h>
#include <lwip/sockets.h>
LightUDP
::
LightUDP
()
:
udp_server
(
-
1
),
server_port
(
0
),
remote_port
(
0
),
remote_ip_int
(
0
)
{}
void
LightUDP
::
begin
(
IPAddress
address
,
uint16_t
port
)
{
server_port
=
port
;
if
((
udp_server
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
==
-
1
)
{
Serial
.
printf
(
"could not create socket: %d"
,
errno
);
return
;
}
int
yes
=
1
;
if
(
setsockopt
(
udp_server
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
yes
,
sizeof
(
yes
))
<
0
)
{
Serial
.
printf
(
"could not set socket option: %d
\n
"
,
errno
);
return
;
}
struct
sockaddr_in
addr
;
memset
((
char
*
)
&
addr
,
0
,
sizeof
(
addr
));
addr
.
sin_family
=
AF_INET
;
addr
.
sin_port
=
htons
(
server_port
);
addr
.
sin_addr
.
s_addr
=
(
in_addr_t
)
address
;
if
(
bind
(
udp_server
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
-
1
)
{
Serial
.
printf
(
"could not bind socket: %d
\n
"
,
errno
);
return
;
}
fcntl
(
udp_server
,
F_SETFL
,
O_NONBLOCK
);
}
void
LightUDP
::
setServer
(
const
char
*
host
,
uint16_t
port
)
{
struct
hostent
*
server
;
server
=
gethostbyname
(
host
);
if
(
server
==
NULL
)
{
Serial
.
printf
(
"could not get host from dns: %d
\n
"
,
errno
);
return
;
}
this
->
remote_ip
=
IPAddress
((
const
uint8_t
*
)(
server
->
h_addr_list
[
0
]));
this
->
remote_ip_int
=
(
uint32_t
)
remote_ip
;
this
->
remote_port
=
port
;
}
void
LightUDP
::
send
(
uint8_t
*
buf
,
size_t
len
)
{
if
(
udp_server
==
-
1
)
{
if
((
udp_server
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
==
-
1
)
{
Serial
.
printf
(
"could not create socket: %d
\n
"
,
errno
);
return
;
}
fcntl
(
udp_server
,
F_SETFL
,
O_NONBLOCK
);
}
struct
sockaddr_in
recipient
;
recipient
.
sin_addr
.
s_addr
=
remote_ip_int
;
recipient
.
sin_family
=
AF_INET
;
recipient
.
sin_port
=
htons
(
remote_port
);
int
sent
=
sendto
(
udp_server
,
buf
,
len
,
0
,
(
struct
sockaddr
*
)
&
recipient
,
sizeof
(
recipient
));
if
(
sent
<
0
)
{
Serial
.
printf
(
"could not send data: %d
\n
"
,
errno
);
return
;
}
}
\ No newline at end of file
simpleVideoRecorder/src/UdpClient.hpp
0 → 100644
浏览文件 @
82d15652
#include <IPAddress.h>
#include <lwip/netdb.h>
#include <lwip/sockets.h>
class
LightUDP
{
private:
int
udp_server
;
IPAddress
remote_ip
;
uint32_t
remote_ip_int
;
uint16_t
server_port
;
uint16_t
remote_port
;
public:
LightUDP
();
void
begin
(
IPAddress
address
,
uint16_t
port
);
void
setServer
(
const
char
*
host
,
uint16_t
port
);
void
send
(
uint8_t
*
buf
,
size_t
len
);
};
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录