» »

[java] Serialiacija in posiljanje preko mreze

[java] Serialiacija in posiljanje preko mreze

alum ::

Poskusam serializirati objekt, ki vsebuje ImageIcon (sliko) in ime. Vendar mi javi Exception, s katerim si res neznam pomagat...kaj delam narobe?

EXCEPTION:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.writeNonProxyDesc(Unknown Source)
at java.io.ObjectOutputStream.writeClassDesc(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeFatalException(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at test.main(test.java:24)

import javax.swing.*;
import java.io.*;
import java.net.*;

public class test{

	public static void main(String arg[]) throws Exception{

		ImageIcon i = new ImageIcon( "test.jpg" );

		User u = new User( "bla", i );
		User n = null;
	
		if(arg.length == 1)
		{
			Socket s = new Socket( "localhost", 5555 );
			
			try
			{

				OutputStream os = s.getOutputStream();
				ObjectOutputStream oos = new ObjectOutputStream( os );

				oos.writeObject( u );
				oos.flush();
				oos.close();

				InputStream is = s.getInputStream();
				ObjectInputStream ois = new ObjectInputStream( is );

				n = (User)ois.readObject();
				ois.close();

				System.out.println( n );
			}
			catch(Exception e){ e.printStackTrace(); }
		
		}
		else
		{


			ServerSocket ss = new ServerSocket( 5555 );
			try
			{
				Socket s = ss.accept();

				OutputStream os = s.getOutputStream();
				ObjectOutputStream oos = new ObjectOutputStream( os );

				oos.writeObject( u );
				oos.flush();
				oos.close();

				InputStream is = s.getInputStream();
				ObjectInputStream ois = new ObjectInputStream( is );

				n = (User)ois.readObject();
				ois.close();

			}
			catch(Exception e){}

		}
	
	}


}


verjetno je napaka v zaporedju ustvarjanja input in output streama, ali pa je napaka v samem ustvarjanju streama...ce v obeh blokih postavim input stream pred output se program neha odzivat...

DCER ::

Nisem prepričan, ampak bi rekel da zato ker zapreš streame. Lahko pa da sem čisto mimo vrezal :D

alum ::

ja nisi mimo vrezal:)

problem je bil, ker sem prehitro zapiral streame:)


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[JAVA] HTTPS client

Oddelek: Programiranje
173167 (1897) peterv6i
»

[Android] Nov tip shranjevanja slike

Oddelek: Programiranje
142175 (1299) urosz
»

[Java] Multi Client chat server

Oddelek: Programiranje
262497 (1768) javaMaster
»

[Java] pošiljanje slik prek porta

Oddelek: Programiranje
51194 (1113) xlarge
»

Kako pošiljanje datotek v JAVI.

Oddelek: Programiranje
141829 (1700) kopernik

Več podobnih tem