473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XmlSerialization over a NetworkStream

Hi,

I am trying to send data over the network using XmlSerialization. The
code shown below is what I am executing.

My problem is that no message is arriving in the Server method, and the
Deserialize method is blocking.

Can someone help me figure out my problem.
Thanks in Advance

public static Semaphore semaphore;

public static void Server()
{
TcpListener listener = new TcpListener(55650);
listener.Start();
Socket socket = listener.AcceptSocket();
Console.WriteLine("client connected");

NetworkStream netStream = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStream);

string msg;
XmlSerializer ser = new XmlSerializer(typeof(string));
semaphore.Acquire();
Console.WriteLine("Waiting for data");
msg = (string)ser.Deserialize(reader);
Console.WriteLine(msg);
Console.WriteLine("terminate");
}

static void Main(string[] args)
{
semaphore = new Semaphore(0, 1);
Thread t = new Thread(new ThreadStart(Runner.Server));
t.Start();

TcpClient client = new TcpClient();
client.Connect("127.0.0.1", 55650);
Console.WriteLine("Connected");
NetworkStream netStream = client.GetStream();

XmlSerializer ser = new XmlSerializer(typeof(string));
StreamWriter writer = new StreamWriter(netStream);
ser.Serialize(writer, "Hello World");
Console.WriteLine("Data Sent");
semaphore.Release();

Console.ReadLine();
}

Nov 21 '05 #1
2 4034
Hi,
I changed the server method to the code below. Now that code is
executing perfectly, and the result being returned is:

<Transfer xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.
org/2001/XMLSchema-instance">
<Data>hello world</Data>

public static void Server()
{
TcpListener listener = new TcpListener(55650);
listener.Start();
Socket socket = listener.AcceptSocket();
Console.WriteLine("client connected");
NetworkStream netStream = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStream);
semaphore.Acquire();
Console.WriteLine("Waiting for data");
Console.WriteLine(reader.ReadLine());
Console.WriteLine(reader.ReadLine());
Console.WriteLine(reader.ReadLine());
Console.WriteLine("terminate");
}

Can some help be given regarding this problem. Thanks in Advance

Nov 23 '05 #2
Following this link, problem was solved. For the interest of anyone,
who wish to learn the trick.

http://www.dotnet247.com/247referenc.../11/57784.aspx

Nov 23 '05 #3

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

Similar topics

1
by: cmjman | last post by:
I have an issue where networkStream.Write doesn't perform its write downstream from my client program until the network stream is closed. I then see the data that was sent appear on the other side....
1
by: Daniel | last post by:
i would like to konw when the data sent so that i can close the streamwriter and networkstream is there some sort of call backs/events i have to implement for this to work? if so how? can i just...
4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
2
by: STom | last post by:
I have just started reading up on XMLSerialization and still do not understand the practical use of this technology. For example, if I have to know the class type on the client and on the web...
0
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was...
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
4
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner...
0
by: Al Wilkerson | last post by:
Hey, Has anyone ever got a "Unable to read data from transport connected" message after reading data from a streamreader composed of a networkstream. For example: Server TcpListener...
7
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.