473,406 Members | 2,816 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,406 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 4036
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
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...
0
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
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
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
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,...

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.