473,789 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object output stream on socket

Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an
object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the
client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.prin tln("in receive");
InputStream in = client.getInput Stream();
ObjectInputStre am receive = new ObjectInputStre am(in);
Object received = receive.readObj ect();
receive.close() ;
in.close();

Here is the code the server is running to send (it throws the exception just
after the println statement):

System.out.prin tln("in send");
OutputStream out = connection.getO utputStream();
System.out.prin tln("got stream one");
ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
sendStream.writ eObject(toSend) ;
sendStream.clos e();
out.close();
Jul 17 '05 #1
2 10462

"Maria Gaitani" <M.*******@warw ick.ac.uk> wrote in message
news:40******** *************** @lovejoy.zen.co .uk...
Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.prin tln("in receive");
InputStream in = client.getInput Stream();
ObjectInputStre am receive = new ObjectInputStre am(in);
Object received = receive.readObj ect();
receive.close() ;
in.close();

Here is the code the server is running to send (it throws the exception just after the println statement):

System.out.prin tln("in send");
OutputStream out = connection.getO utputStream();
System.out.prin tln("got stream one");
ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
sendStream.writ eObject(toSend) ;
sendStream.clos e();
out.close();


If you close the streams you also close the underlying socket connections.
Is that your intention? If not simply flush the streams instead.

Silvio Bierman
Jul 17 '05 #2
Thank you very much for your time and help !!
I will try that straight away !

Maria

"Maria Gaitani" <M.*******@warw ick.ac.uk> wrote in message
news:40******** *************** @lovejoy.zen.co .uk...
Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.prin tln("in receive");
InputStream in = client.getInput Stream();
ObjectInputStre am receive = new ObjectInputStre am(in);
Object received = receive.readObj ect();
receive.close() ;
in.close();

Here is the code the server is running to send (it throws the exception just after the println statement):

System.out.prin tln("in send");
OutputStream out = connection.getO utputStream();
System.out.prin tln("got stream one");
ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
sendStream.writ eObject(toSend) ;
sendStream.clos e();
out.close();

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5228
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote peer. I have no problem connecting the peers and streaming Network Streams. When the incoming data is finished recieving, I act upon it. This works great as long as all of the code is inside my form. I want to build the networking code into a...
8
12668
by: rawCoder | last post by:
Hi All, I need some advanced samples or references for passing custom objects over the network using sockets. Without using Remoting what are other options in .NET Framework for this binary serialization. Thank You rawCoder
0
4267
by: vinothgsd | last post by:
Hi, I have created Client/Server application. In that Client side Program i have used Asynchronous Callback method for send and receive the stream. In the Receive method I want to make the Buffer (i.e) byte to an object. How can i do this except using BinaryFormatter. I know what type of object i'm expecting. So is it possible to send the expected object to ReceiveCallBack method? If it is poosible Then there i can deserialize and get...
7
3156
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the same time. My scenario is a small server application that listens on a particular TCP port. I am sending streams of data to it via a client app. Inside
5
12988
by: ad | last post by:
I used use SharpZipLib to compress files in disk. But now I want to compress stream into another stream in memory(the stream not associated with disk file) My pseudo is: Stream InputStream; Stream OutPutStream; DataSet1.WriteXml(InputStream);
4
1353
by: Lee Gillie | last post by:
What I am hoping to do is make a constructor for a derived class that can accept an instance of the base class. Maybe this just is not possible? I am working with the new SSLStream in the 2005 beta. They came up with what seems to be an awkward object model to me. The SSLStream has nearly the same member signature as a NetworkStream. Both are derived from Stream. But in both cases you need a TCPClient instance to get them going. This...
0
1630
by: ChopDown | last post by:
Hi, I want to send/receive a serializable object in socket: ==========sender========== Dim MyMessage As New MessageClass.Message() Dim client As New TcpClient client.Connect(My.MySettings.Default.Server, My.MySettings.Default.ServerPort) Dim clientStream As NetworkStream = client.GetStream Dim serializer As IFormatter = New BinaryFormatter() serializer.Serialize(clientStream, MyMessage)
2
2766
by: White Spirit | last post by:
I have a function within an application where a client connected to a server continuously sends data. The code on the server side is of the following form: Socket socket = receiveSocket; NetworkStream networkStream = new NetworkStream (socket); System.IO.StreamReader streamReader = new System.IO.StreamReader (networkStream); while (socket.Connected)
2
1820
by: darthghandi | last post by:
I am creating a listener class that listens for incoming connections. When I get an incoming connection, I want to signal an event to happen and pass that connected socket to a different thread for the real work. I want to continue to listen for more connections. So is the socket I pass with the delegate a reference or a value? I thought this might work: public delegate void AcceptConnection(Socket sock); public class Listener
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.