문제

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);

?>
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top