sofastack / sofa-bolt

SOFABolt is a lightweight, easy to use and high performance remoting framework based on Netty.
https://www.sofastack.tech/projects/sofa-bolt/
Apache License 2.0
2.43k stars 859 forks source link

How to create udp protocol? I read the default is tcp #225

Open B1gB1gRAin opened 4 years ago

B1gB1gRAin commented 4 years ago

Your question

该如何创建udp 协议呢?我看了下默认是tcp的?

如果我要创建udp相关的服务端 我需要手动去扩展这部分代码吗 ` this.bootstrap = new ServerBootstrap(); this.bootstrap .group(bossGroup, workerGroup) .channel(NettyEventLoopUtil.getServerSocketChannelClass()) .option(ChannelOption.SO_BACKLOG, ConfigManager.tcp_so_backlog()) .option(ChannelOption.SO_REUSEADDR, ConfigManager.tcp_so_reuseaddr()) .childOption(ChannelOption.TCP_NODELAY, ConfigManager.tcp_nodelay()) .childOption(ChannelOption.SO_KEEPALIVE, ConfigManager.tcp_so_keepalive()) .childOption(ChannelOption.SO_SNDBUF, tcpSoSndBuf != null ? tcpSoSndBuf : ConfigManager.tcp_so_sndbuf()) .childOption(ChannelOption.SO_RCVBUF, tcpSoRcvBuf != null ? tcpSoRcvBuf : ConfigManager.tcp_so_rcvbuf());

    // set write buffer water mark
    initWriteBufferWaterMark();`

感谢平台 感谢开源

Your scenes

需要udp 消息和tcp的广播

Your advice

describe the advice or solution you'd like

Environment

sofastack-bot[bot] commented 4 years ago

Hi @B1gB1gRAin, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

Your question How to create udp protocol? I read that the default is tcp? If I want to create a UDP related server, do I need to manually extend this part of the codethis.bootstrap = new ServerBootstrap(); this.bootstrap .group(bossGroup, workerGroup) .channel( NettyEventLoopUtil.getServerSocketChannelClass()) .option(ChannelOption.SO_BACKLOG, ConfigManager.tcp_so_backlog()) .option(ChannelOption.SO_REUSEADDR, ConfigManager.tcp_so_reuseaddr()) .childOption(ChannelOption.TCP_NODELAY, ConfigManager.tcp_nodelay()) .childOption SO_KEEPALIVE, ConfigManager.tcp_so_keepalive()) .childOption(ChannelOption.SO_SNDBUF, tcpSoSndBuf != null? TcpSoSndBuf: ConfigManager.tcp_so_sndbuf()) .childOption(ChannelOption.SO_RCVBUF, tcpSoRcvBuf !=v cpt = (?vt?)) / set write buffer water mark initWriteBufferWaterMark(); Thanks to the platform thanks to open source ### Your scenes udp message and tcp broadcast ### Your advice describe the advice or solution you'd like ### Environment- SOFABolt version:1.6.1-JVM version (eg java -version):1.8-OS version (eg uname -a):win7-Maven version:3.6-IDE version:idea

B1gB1gRAin commented 4 years ago

How to create udp protocol?


this.bootstrap
.group(bossGroup, workerGroup)
.channel(NettyEventLoopUtil.getServerSocketChannelClass())
.option(ChannelOption.SO_BACKLOG, ConfigManager.tcp_so_backlog())
.option(ChannelOption.SO_REUSEADDR, ConfigManager.tcp_so_reuseaddr())
.childOption(ChannelOption.TCP_NODELAY, ConfigManager.tcp_nodelay())
.childOption(ChannelOption.SO_KEEPALIVE, ConfigManager.tcp_so_keepalive())
.childOption(ChannelOption.SO_SNDBUF,
tcpSoSndBuf != null ? tcpSoSndBuf : ConfigManager.tcp_so_sndbuf())
.childOption(ChannelOption.SO_RCVBUF,
tcpSoRcvBuf != null ? tcpSoRcvBuf : ConfigManager.tcp_so_rcvbuf());

    // set write buffer water mark
    initWriteBufferWaterMark();```
B1gB1gRAin commented 4 years ago

@xmtsui @zhaojigang @dbl-x

fantow commented 4 years ago

I don’t think it’s supported UDP yet,but you can Try like this:

BootStrap bootstrap = new BootStrap() b.group(bossGroup) .channel(NioDatagramChannel.class) .option(ChannelOption.SO_BROADCAST, true)

dbl-x commented 3 years ago

当前都是基于TCP协议的版本,没有验证过UDP。 建议对照Netty的UDP使用来尝试是否可以拓展,如果有没法拓展的接口请联系我。欢迎提PR来共建!