Java: EOFException in networking -


i new networking , getting eofexception when trying run myclient.java.

myserver.java

public class myserver {     public static void main(string[] args) {         serversocket serversocket = null;         try {             serversocket = new serversocket(4321);         } catch (ioexception e) {             e.printstacktrace();         }         while(true) {             try {                 socket socket = serversocket.accept();                 outputstream os =socket.getoutputstream();                 outputstreamwriter osw = new outputstreamwriter(os);                 bufferedwriter bw = new bufferedwriter(osw);                 bw.write("hello networking");                  bw.close();                 socket.close();             } catch (ioexception e) {                 e.printstacktrace();             }         }     } } 

myclient.java

public class myclient {     public static void main(string[] args) {         socket socket = null;         try {             socket = new socket("127.0.0.1", 4321);             inputstream = socket.getinputstream();             datainputstream dis = new datainputstream(is);             system.out.println(dis.readutf());              dis.close();             socket.close();         } catch (unknownhostexception e) {             e.printstacktrace();         } catch (connectexception e) {             system.err.println("could not connect");         } catch (utfdataformatexception e) {             system.err.println("if bytes not represent valid modified utf-8 encoding of string");         } catch (eofexception e) {             system.err.println("if input stream reaches end before reading bytes");         } catch (ioexception e) {             e.printstacktrace();         }     } } 

i if input stream reaches end before reading bytes error , error seems arise dis.readutf() call.

could me understand missing? trying trying read server writes client when gets connected, hello networking.

thanks.

the problem in server code should use dataoutputstream.writeutf(string str) write socket if want read datainputstream.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -