ObjectStreams

I'm trying to convert a simple chat board to an object board (ie pass objects intead of text throught the socket).

When I try to declare my new streams the code freezes and goes no futher.

fDataIn = new ObjectInputStream(socket.getInputStream());
fDataOut = new ObjectOutputStream(socket.getOutputStream());

Can anyone help with some advive or some code?
cmg05Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbormannCommented:
try something like

fDataIn = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));

fDataOut = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
0
rainmalCommented:
Well I think the problem here is that you cannot get the inputstream and/or the outputstream to the socket.(For some reason)

Keep a system out b/w the two stream init's and see where exactly it fails

I would help if you could post some code.

0
mwibbelsCommented:
I've seen this happening: it was due to the ObjectInputStream constructor trying to read a header from its underlying input stream (in your case the socket) before it returns. This means that the code will block until 'the other side' (the one writing to that socket, server) does new ObjectOutputStream(socket.getOutputStream());

so if you're using a server with a ServerSocket, then do:

Socket s = serverSocket.accept();
// switching the next two calls will block the server!
out = new ObjectOutputStream(s.getOuputStream());
in = new ObjectInputStream(s.getInputStream()); // blocks until the client creates the output stream

And in the client:

Socket s = new Socket(host,port);
out = new ObjectOutputStream(s.getOuputStream()); // unblocks the server
in = new ObjectInputStream(s.getInputStream()); // blocks until the server
creates the output stream

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mbormannCommented:
mwibbels,
long time no see u pardner
:)

Now that u pointed out the real reason ,I recall that a friend had answered it for me as my very first question.
Thanks for that ,and I think this happens in every OutputStream that is u have to put it b4 InputStream,isn't it so?

Cheers
0
mwibbelsCommented:
Yep, you're right about 'Output b4 Input'

And: I've been watching EE, but there seem to be a lot more experts that are also (in my view at least) a lot more 'answer-trigger-happy'.

But that's just the talk of an old guy longing for past times, when the grass was greener, the people were nicer, ..... ;-)
0
mbormannCommented:
>>>when the grass was greener, the people were nicer

The times they are a changing and you gotta change alonga them.
You dont seem to be infected by that fever ,why not? I was and now am changed.
:)
0
mwibbelsCommented:
>> I was and now am changed.
Do you have some guru I can send money to and be changed myself? (No offence, just kidding)
0
mbormannCommented:
>>>Do you have some guru I can send money to

no need to ,my teacher is named 'Experience' and taught me

"Good judgment comes from experience, and
experience comes from bad judgment"

0
rainmalCommented:
MB
>>I recall that a friend had answered it for me as my very first question.

I think I have a pretty good idea of who that friend might be.

;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-)
0
cmg05Author Commented:
Thanks man,

I knew it would be sonthing simple.  But I could have been there for years stuffing with Serializable etc befor I simply switched them around.
0
mbormannCommented:
rainmal,

no need to laugh so much man,
cmg05 that guy was crying for 2 days b4 he got it by sheer mix and match what our purists would say Permutations and Combinations

:)
0
rainmalCommented:
You know what they say MB....

HOPE IS ALWAYS THE LAST TO DIE.

;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.