objectinputstream

Java ObjectInputStream hanging

眉间皱痕 提交于 2019-12-01 04:43:00
I am feeling really stupid right now guys.... basically I am connecting over TCP on a local machine... and when I try to make the In/out streams at the client it wont get passed creating the object input stream. What gives? This stops after printing 2... no exceptions or anything... This isn't the first time I've used this class which is partialy why I am puzzled. try { System.out.println("1"); mySocket = new Socket("localhost", 11311); System.out.println("12"); oos = new ObjectOutputStream(mySocket.getOutputStream()); System.out.println("2"); ois = new ObjectInputStream(mySocket

Java ObjectInputStream hanging

青春壹個敷衍的年華 提交于 2019-12-01 02:42:31
问题 I am feeling really stupid right now guys.... basically I am connecting over TCP on a local machine... and when I try to make the In/out streams at the client it wont get passed creating the object input stream. What gives? This stops after printing 2... no exceptions or anything... This isn't the first time I've used this class which is partialy why I am puzzled. try { System.out.println("1"); mySocket = new Socket("localhost", 11311); System.out.println("12"); oos = new ObjectOutputStream

Java - Listening to a socket with ObjectInputStream

浪子不回头ぞ 提交于 2019-11-30 20:31:40
Ok so , i have a thread class called 'Client' every time the server accepts a connection it creates a new Client....The run method listens for messages from the client and i am useing ObjectInputStream .. do { ObjectInputStream in = null; try { in = new ObjectInputStream(socket.getInputStream()); String message = (String) in.readObject(); System.out.println(message); } catch (ClassNotFoundException ex) { isConnected = false; System.out.println("Progoramming Error"); } catch (IOException ex) { isConnected = false; System.out.println("Server ShutDown"); System.exit(0); } } while(isConnected);

Exception.getCause() returning null when trying to find the source of an exception

百般思念 提交于 2019-11-30 14:41:54
why does System.out.println(e.getCause()); gives null ? And can store whole HashSet collection like this? private void saving() throws IOException, ClassNotFoundException { ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile))); out.writeObject(c); } catch (java.io.NotSerializableException e) { System.out.println(e.getCause()); } finally { out.close(); } } Used printStackTrace() instead of getCause() java.io.NotSerializableException: Data$1 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180) at java.io

Java - Listening to a socket with ObjectInputStream

妖精的绣舞 提交于 2019-11-30 05:01:09
问题 Ok so , i have a thread class called 'Client' every time the server accepts a connection it creates a new Client....The run method listens for messages from the client and i am useing ObjectInputStream .. do { ObjectInputStream in = null; try { in = new ObjectInputStream(socket.getInputStream()); String message = (String) in.readObject(); System.out.println(message); } catch (ClassNotFoundException ex) { isConnected = false; System.out.println("Progoramming Error"); } catch (IOException ex) {

Performance issue using Javas Object streams with Sockets

蹲街弑〆低调 提交于 2019-11-29 09:43:30
I'm trying to do local IPC using Sockets and Object streams in Java however I'm seeing poor performance. I am testing the ping time of sending an object via an ObjectOutputStream to receiving a reply via an ObjectInputStream over a Socket. Here's the Requestor: public SocketTest(){ int iterations = 100; try { Socket socket = new Socket("localhost", 1212); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); double start = System.currentTimeMillis(); for (int i = 0; i <

Java Socket Programming

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:42:37
I am building a simple client/server application using java sockets and experimenting with the ObjectOutputStream etc. I have been following the tutorial at this url http://java.sun.com/developer/technicalArticles/ALT/sockets starting half way down when it talks about transporting objects over sockets. See my code for the client http://pastebin.com/m37e4c577 However this doesn't seem to work and i cannot figure out what's not working. The code commented out at the bottom is directly copied out of the tutorial - and this works when i just use that instead of creating the client object. Can

Continuously read objects from an ObjectInputStream in Java

[亡魂溺海] 提交于 2019-11-28 14:33:03
I have a problem using an ObjectInputStream and I have been struggling with it for 2 days now. I tried to search for a solution but unfortunately found no fitting answer. I am trying to write a client/server application in which the client sends objects (in this case a configuration class) to the server. The idea is that connection keeps alive after sending the object so it is possible to send a new object if necessary. Here are the important parts of my client code: mSocket = new Socket("192.168.43.56", 1234); mObjectIn = new ObjectInputStream(mSocket.getInputStream()); mObjectOut = new

Must server & client have reverse sequence of claiming ObjectOutputStream & ObjectInputStream?

∥☆過路亽.° 提交于 2019-11-28 11:49:12
In my experiment, if Server has this: ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); then client side has to do this, in the opposite order: ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); Otherwise server and client will deadlock. What's the reason for this? and is there a formal API spec for it? Yes. I see how this might happen. The

java.io.EOFException while writing and reading froma servlet

被刻印的时光 ゝ 提交于 2019-11-28 11:40:55
I have the following code on the applet side: URL servlet = new URL(appletCodeBase, "FormsServlet?form=requestRoom"); URLConnection con = servlet.openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/octet-stream"); ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); out.writeObject(user);//user is an object of a serializable class out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(con.getInputStream()); status = (String)in.readObject(); in.close(); if("success".equals(