[英]TFTP client based on java NIO
I am trying to implement TFTP client using Java NIO. 我正在尝试使用Java NIO实现TFTP客户端。 But it leads to error: 但这会导致错误:
network error: Address already in use: bind 网络错误:地址已在使用中:绑定
Code snippet is shared here. 此处共享代码段。
Selector selector = Selector.open();
DatagramChannel channel = DatagramChannel.open();
InetSocketAddress isa = new InetSocketAddress("10.86.4.250",69);
channel.socket().bind(isa);
channel.configureBlocking(false);
As I am new to this networking concept, I couldn't understand the cause. 由于我是这个网络概念的新手,所以我无法理解原因。 Any help in resolving this issue is highly appreciated. 非常感谢您对解决此问题的任何帮助。
If you're developing a client, you should .connect()
to a socket, rather than bind()
'ing (that's for the server), eg.: 如果要开发客户端,则应.connect()
插入套接字,而不是bind()
(用于服务器),例如:
DatagramChannel channel = DatagramChannel.open();
channel.connect( new InetSocketAddress( "10.86.4.250" , 69 ) );
...
Cheers, 干杯,
Have a look at how TFTPClient client from implemented. 看一下TFTPClient客户端如何实现的。
Methods initialiseSocket
and sendTftpPacket
are more interesting. 方法initialiseSocket
和sendTftpPacket
更有趣。
Basically you do not need to bind the socket(). 基本上,您不需要绑定socket()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.