android - EADDRINUSE When creating server socket on google glass -



android - EADDRINUSE When creating server socket on google glass -

i developing google glass/android application. video streaming application has server/client setup phone/glasses server , hooks pc session description playing video. works great on android , runs fine seek test on google glass throws error @ line

ssocket = new serversocket(sport);

the exception message says "eaddrinuse" i'm assuming means port opened never opened it. if had opened , programme didn't close changed port couple of times , still says it's in use.

thanks

tyler,

google glass, android, consistently have many of it's ports occupied applications running in background. when creating socket server hear on, have 2 choices:

1) have predetermined list of ports can take have server hear on.

if take this, can have datastructure (list, queue, heap [if have priority of ports use], etc) contain of ports, can traverse them until find open port.

this can achieved in next manner:

private serversocket allocateport(list<integer> myarray) throws ioexception { (int individualport : myarray) { seek { homecoming new serversocket(individualport); } grab (ioexception io) { continue; // exception thrown if port in use. it's ok, let's seek port. } } // when no ports available, let's throw exception stating unable find open port. throw new ioexception("we unable find open port"); }

then invoke method within follows:

int[] arrayofports = {5000, 5001, 5002, 8000, 8001, 8002, 8003}; list<integer> myarray = new arraylist<>(); myarray = intstream.of(arrayofports).boxed().collect(collectors.tolist()); serversocket ssocket = allocateport(myarray);

2) if don't mind port hear in on, can utilize constructor pick available port.

this can achieved follows:

serversocket ssocket = new serversocket(0);

you can read more on serversocket's javadocs. notice under parameter's subsection:

port - port number, or 0 utilize port number automatically allocated.

please allow me know if have questions!

android sockets google-glass google-gdk

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -