Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 5th, 2008, 02:51 PM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 70 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 12 m 53 sec
Reputation Power: 4
Socket programming help

hi,

ok this is what i'm trying to do. i'm trying a simple server/client program to send a string and then an object(vector). i can send them both seperately but not both together. anyone know why?

on the server side i have
sock = new ServerSocket(serverPort);
clientSocket = sock.accept();

o = new DataOutputStream (new BufferedOutputStream (clientSocket.getOutputStream ()));
vectorObj = new ObjectOutputStream(clientSocket.getOutputStream());

Vector handlers = new Vector();
handlers.addElement("bananas");
handlers.addElement("milk");
handlers.addElement("coffee");

o.writeUTF ("blah blah");
o.flush();
vectorObj.writeObject(handlers);

clientSocket.close();
sock.close();

and on the client side i first read the string (blah blah) and it works fine, but when i try to read the object it doesn't work.
if i comment out o.writeUTF ("blah blah"); and o.flush(); i can then read the object....

any ideas? cheers
ciaran

Reply With Quote
  #2  
Old May 5th, 2008, 09:44 PM
stdunbar stdunbar is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 1,704 stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 15 h 44 sec
Reputation Power: 325
Send a message via ICQ to stdunbar Send a message via Yahoo to stdunbar
It sounds like you're doing the correct thing but we need a complete code sample. It's very difficult to determine what the issue is with just a partial sample.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
  #3  
Old May 6th, 2008, 04:24 AM
Hugh of Borg's Avatar
Hugh of Borg Hugh of Borg is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2004
Location: Switzerland
Posts: 577 Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 21 h 48 m 32 sec
Reputation Power: 86
I suspect that you accidentally read a part of the object as well and thus "corrupt" the object in the stream...

You should be able to send String objects through the ObjectOutputStream. Try that and see if it helps.
Comments on this post
tagmanadvance agrees: Beat me to it =)
__________________
- Hugh of Borg

The first thing young borg are taught: Keep away from Microsoft software!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Socket programming help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway