Java socket hanging when inside of java servlet -


so i've been trying figure out how send messages between arduino , java servlet (tomcat) , have been bumping problems. i'm using code in java servlet:

serversocket server;     //socket server port on listen     int port = 9876;     string message = "";    //create socket server object    server = new serversocket(port);    system.out.println("server socket created");     //keep listens indefinitely until receives 'exit' call or program terminates    while(true){        system.out.println("waiting client request...");         //creating socket , waiting client connection        socket socket = server.accept();         bufferedreader buff = new bufferedreader(new inputstreamreader (socket.getinputstream()));        system.out.println("input stream established");         message = buff.readline();         system.out.println("message received: " + message);         buff.close();        socket.close();         //terminate server if client sends exit request        if(message.equalsignorecase("exit")) break;    }     system.out.println("shutting down socket server!!");     //close serversocket object    server.close(); 

but it's hanging on

socket socket = server.accept(); 

line. assume because messages i'm sending arduino aren't arriving. on arduino side of things, client:

if (client.connect(ip, 9876)) {       serial.println("connected");       client.println("12345678");       serial.println("message sent");     } else {       serial.println("connection failed");     } 

not it. now, i've tried sending http post request, without success (surely i'm doing incorrectly, don't know how it, i've tried while). know horrifically written, i'm open learning guys today. weird thing works how want when put java server code in new regular java project. can me figure out? why hanging in servlet not in regular java project?


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -