[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

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?
0
cmg05
Asked:
cmg05
  • 5
  • 3
  • 3
  • +1
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now