473,513 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send/receive a serializable object in socket?

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)
clientStream.Close()

===========receive==========
Dim serializer As IFormatter = New BinaryFormatter()
Dim listener As TcpListener = New TcpListener(IPAddress.Any,
My.MySettings.Default.Port)
listener.Start()
Dim client As TcpClient = listener.AcceptTcpClient
Dim clientStream As New NetworkStream(client.Client, False)
Dim ReciveMessage As MessageClass.Message =
TryCast(serializer.Deserialize(clientStream2), MessageClass.Message)
MsgBox(ReciveMessage.ToString)

===============================

there are no problem. But when I put the receive function to a while
loop. I found that I can't get the second object. It shows some
exception.(in java, I can use Stream.flush; Stream.reset to fix it, but
I can't find the same in .net). Anyone can tell me
how to send/receive a serializable object in socket? (I want to write a
chat server/client, any other way?)
Thanks in advance.

Dec 13 '06 #1
0 1608

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

Similar topics

1
5354
by: Kitchen Bin | last post by:
Hi. I am trying to use Sockets to do multiple Send and Receives via HTTP (not simultaneously). A first pair of Send/Receives works fine and sure enough I receive HTML back, but the next...
1
2696
by: EppO | last post by:
I wrote a small server/client app. I created a class for my customized socket object using (synchronous) Sockets functions for both server and client use. When client connects to server, if It...
3
7738
by: Dirk Reske | last post by:
Hey, I have following struct: struct Packet { string Command; string Args; byte Data; }
2
2694
by: Matt | last post by:
Hi, I've got a C# client/service application using a Socket object to communicate. I have a socket bug that I can't solve without kludged-code. Does anyone know a more elegant solutions? Is this...
2
5273
by: Alpha | last post by:
Hi, I'm able to make connection to a server using socket connection. However, when I send a command string the server just ignores it. All command string needs to start with "0xF9" at Byte 0. ...
5
1610
by: nicolas ETIENNE | last post by:
Hello, I want to send through Socket a struct So, i'd like to do, as I did before in C++, something like send((void*)myStruct); where myStruct is a struct with basic types
11
7676
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running...
3
4264
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
3138
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
0
7391
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,...
0
7553
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...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
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...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3247
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.