Question

Trying to send data using C# over a TCP connection.

string reply = "<?xml version='1.0' standalone='yes'?>
<root><ele1 type='2'/><author>patrick</author>
<address>spain</address></root>";

Here is where I think the problem is:

reply = format.ProcessMessage(message); - this method returns the above string
byte[] breply = System.Text.Encoding.ASCII.GetBytes(reply);
stream.Write(breply, 0, breply.Length);

The response on the client's end is: patrickspain But I want the entire XML string to be sent. Anyone has any idea of how to fix this?

The following is my PHP client code:

<?php

$host    = "127.0.0.1";
$port    = 7890;
$message = "Test Message";
echo "Message To server :".$message;
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");
socket_write($socket, $message, strlen($message)) or die("Could not send data\n");
$result = socket_read ($socket, 1024) or die("Could not read server response\n");
echo "Reply From Server  : ".$result;
socket_close($socket);

?>
Was it helpful?

Solution

The browser receives your data just fine. It's trying to show XML as HTML, which means you'll just see the inner text of each node, in this case the author's name.

Right-click the page and click "View Source" to see what the browser received. You can also use a tool like Fiddler to debug HTTP traffic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top