29 Kasım 2022 Salı

BindException Sınıfı

Giriş
Şu satırı dahil ederiz.
import java.net.BindException;
Hata 1
Genellikle hata şöyle. Yani server socket tarafından alınmak istenilen port zaten kullanılıyor
java.net.BindException: Address already in use
Linux
Bu portu kullanan process'i bulmak için şöyle yaparız
lsof -i:8080
Hata 2
Bazen hata şöyle
java.net.BindException: Cannot assign requested address: bind
Wndows'ta buna sebep olan bir kod şöyle
InetAddress address = InetAddress.getByName("224.0.0.219");
DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET);
datagramChannel.bind(new InetSocketAddress(address, 10863));
Açıklaması şöyle
I am trying to write an application that listens to a number of multicast groups using Windows sockets.

The problem I'm running in to is that when I go to bind the socket, if I try to bind to the multicast group address and port this fails with WSAEADDRNOTAVAIL. If I instead bind to INADDR_ANY and the port, then I can still receive other unrelated traffic destined for the same port.

When I implemented the same thing in Linux, I didn't have any issues binding to the multicast address (in fact, I saw it recommended several places to avoid getting unrelated traffic for the port).

Is this just not available with Windows sockets? I assume I could filter traffic myself by using WSARecvFrom and peeking at the headers, but I'd rather a simple solution if one exists.

Also, this is running on Windows Server 2008.
Burada kişi sadece Multicast trafiği almak istiyor, Unicast trafiği istemiyor. Bu yüzden bind() çağrısına multicast address + port numarasını geçiyor. Ama bu kod Windows'ta çalışmıyor. 

Yani anladığım kadarıyla Windows'ta sadece Multicast trafiği dinlemek imkansız. Multicast + Unicast trafik olacak şekilde çalışıyor. Yani şöyle yapmak gerekir
datagramChannel.bind(new InetSocketAddress(10863));


Hiç yorum yok:

Yorum Gönder