Java api for bluetooth mac books9/21/2023 In the previous section, we saw just one of these approaches the getByName() static method. In this section, we will explore the other available APIs for retrieving the available interfaces. We know that if we want our local address to be localhost, the first snippet would suffice if we just added the binding code.Īdditionally, we would never really have to go through all the several steps since localhost has one well-known address, 127.0.0.1 and we can easily bind the socket to it. This does not really say anything special about the API. So binding to any of these addresses will guarantee communication through this interface. So we retrieve the network interface attached to lo first, retrieve the addresses attached to it, create a socket, bind it to any of the enumerated addresses which we don't even know at compile time and then connect.Ī NetworkInterface object contains a name and a set of IP addresses assigned to it. nnect(new InetSocketAddress(address, port)) Socket.bind(new InetSocketAddress(nifAddresses.nextElement(), 0)) Just for demonstration purposes, let's assume we want the connection over the loopback interface, by convention, its name is lo, at least on Linux and Windows systems, on OSX it is lo0: NetworkInterface nif = NetworkInterface.getByName("lo") Įnumeration nifAddresses = nif.getInetAddresses() We will make an assumption here we don't know the address but we know the name.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |