1

I am trying to implement TFTP client using Java NIO. 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.

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
Abinaya LK
  • 35
  • 6

2 Answers2

1

If you're developing a client, you should .connect() to a socket, rather than bind()'ing (that's for the server), eg.:

DatagramChannel channel = DatagramChannel.open();
channel.connect( new InetSocketAddress( "10.86.4.250" , 69 ) );
...

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
0

Have a look at how TFTPClient client from implemented.
Methods initialiseSocket and sendTftpPacket are more interesting.

Basically you do not need to bind the socket().

Cristian Sevescu
  • 1,364
  • 8
  • 11