Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
B1gB1gRAin opened this issue Jun 16, 2020 · 5 comments
Open

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

B1gB1gRAin opened this issue Jun 16, 2020 · 5 comments
Labels

Comments

@B1gB1gRAin
Copy link

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

  • SOFABolt version:1.6.1
  • JVM version (e.g. java -version):1.8
  • OS version (e.g. uname -a):win7
  • Maven version:3.6
  • IDE version:idea
@sofastack-bot sofastack-bot bot changed the title 该如何创建udp 协议呢?我看了下默认是tcp的 How to create udp protocol? I read the default is tcp Jun 16, 2020
@sofastack-bot
Copy link

sofastack-bot bot commented Jun 16, 2020

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 code 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 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
Copy link
Author

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
Copy link
Author

@xmtsui @zhaojigang @dbl-x

@fantow
Copy link

fantow commented Jun 16, 2020

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
Copy link
Contributor

dbl-x commented Aug 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants