473,396 Members | 2,129 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,396 software developers and data experts.

how to send xml data over tcp/ip

Hi everyone. I am new to programming and trying to learn as I go however am struggling here and any assistance please I greatly appreciate.

I am trying to send hardcoded xml tags to a server that only received xml tags for processing and this is the code I have which is not working. Please help.
public void Connect(string serverIP, string message)
{
string output = "";

try
{
// Create a TcpClient.
// The client requires a TcpServer that is connected
// to the same address specified by the server andport
// combination.
Int32 port = 4566;
TcpClient client = new TcpClient(serverIP, port);

// Translate the passed message into ASCII and store it as a byte array.
Byte[] data = new Byte[4000];
data = System.Text.Encoding.UTF8.GetBytes(message);

// Get a client stream for reading and writing.
NetworkStream stream = client.GetStream();

// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);

// Buffer to store the response bytes.
data = new Byte[256];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
//output = "Received: " + responseData;
//Response.Write(output);

// Close everything.
client.Close();
stream.Close();

}
catch (ArgumentNullException e)
{
output = "ArgumentNullException: " + e;
//MessageBox.Show(output);
Response.Write(output);
}
catch (SocketException e)
{

output = "SocketException: " + e.ToString();
//MessageBox.Show(output);
Response.Write(output);
}
}

protected void Button1_Click(object sender, EventArgs e)
{
// In this code example, use a hard-coded
// IP address and message.

string serverIP = "localhost";
string message = "<NHServerMessage protocol_version=\"1.0\"><BASIC_REQUEST_INFO request_type=\"S\" request_id=\"-1\"/><DATA_LIST_NAME value=\"names\"/><SEARCH_NAME SN=\"Bob\" GN=\"Anderson\"/></NHServerMessage>";
Connect(serverIP, message);


}

PLEASE HELP. THANKS A BUNCH!
Jul 31 '07 #1
3 4329
Any Ideas, HELP PLEASE
Aug 1 '07 #2
Plater
7,872 Expert 4TB
Is UTF8 the correct encoding type? I have always used ASCII.
You might have to include the byte-order mark at the begining if that is true?(or does that only apply to UTF16?)

What does the server say?
Aug 1 '07 #3
it doesn't read the data at all doesn't do anything

Unable to read one byte in receiveTerminatedStringWithTimeout
Aug 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
2
by: Jacques | last post by:
Hello All, This sends an email message OK. But, how do I attach a file? // create server SMTP with port 25 string ServSMTP = "mycompany.com"; string sFrom = "support@mycompany.com";...
4
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
13
by: Manfred Braun | last post by:
Hi All, I am trying to understand the blocking method socket.Send(). The call blocks as expected, but does this mean, it returnes after the underlying TCP layer got a confirmation, that the send...
4
by: ad | last post by:
I want to send a DataSet to WebService, but the DataSet if too huge(there about 50000 records, and 50 fields every record). My solution is 1.save the DataSet as XML file, 2.zip the XML file. 3....
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
11
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...
2
by: yvan | last post by:
Hi, Here is my client/server scenario: Step1: Client connects to server and sends data sucessfully (using Socket.Send()). Step2: Server gracefully exists (calls Socket.Shutdown() and...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.