473,748 Members | 4,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to send xml data over tcp/ip

3 New Member
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(serve rIP, port);

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

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

// Send the message to the connected TcpServer.
stream.Write(da ta, 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(dat a, 0, data.Length);
responseData = System.Text.Enc oding.ASCII.Get String(data, 0, bytes);
//output = "Received: " + responseData;
//Response.Write( output);

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

}
catch (ArgumentNullEx ception e)
{
output = "ArgumentNullEx ception: " + e;
//MessageBox.Show (output);
Response.Write( output);
}
catch (SocketExceptio n e)
{

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

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

string serverIP = "localhost" ;
string message = "<NHServerMessa ge protocol_versio n=\"1.0\"><BASI C_REQUEST_INFO request_type=\" S\" request_id=\"-1\"/><DATA_LIST_NAM E value=\"names\"/><SEARCH_NAME SN=\"Bob\" GN=\"Anderson\"/></NHServerMessage >";
Connect(serverI P, message);


}

PLEASE HELP. THANKS A BUNCH!
Jul 31 '07 #1
3 4439
Newbie27
3 New Member
Any Ideas, HELP PLEASE
Aug 1 '07 #2
Plater
7,872 Recognized Expert Expert
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
Newbie27
3 New Member
it doesn't read the data at all doesn't do anything

Unable to read one byte in receiveTerminat edStringWithTim eout
Aug 1 '07 #4

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

Similar topics

2
20747
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 But the problem occures when i want to send a data with & sign (i.e: Firm=F&B). I try to solve this problem with using boundary, but i failed. Any idea!?
2
5765
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"; string sTo = "webmaster@bmycompany.com"; string sSubject = "Subject Test";
4
8072
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 has data send to server. 2. Client send the buffer block size. 3. Client send the actual buffer to the server. 4. Server send a flag 1 to client indicating that the buffer has been successfully receeived. 5. The next loop until all data of the...
13
8104
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 data was received by the socket on the remote end? Can I count on that? Do I understand TCP correctly in that, it gives confirmation ? I do not expect, that a .Net based receiver got that data when socket.Send() terminates!
4
18545
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. send the zip file to WebService. 4. Unzip the zip file to XML. 5. Load XML file into DataSet. 6.Bulk copy the XML file to DataBase.
9
3154
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 other page, or is there something else like a stream which will be like a file. I am attempting to get a way from writing out a file and then having to give the page that I am posting to the file name. Instead I would like to just from asp.net...
11
7723
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 the app, even the first time. The application will be required to be sending out repeated emails, about one every second or two. Must this be done asynchronously? Thank you. -Greg I get the generic error messages;
2
13152
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 Socket.Close()). I see the server connection status go from ESTABLISHED to FIN_WAIT2, the client connection go from ESTABLISHED to WAIT_CLOSE. Step3: client.Send() succeeds and return the number of bytes sent (over the closed connection!)
14
11918
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 doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call NetworkStream ns = client.GetStream(); to get a stream stream.Read(buffer, 0, buffer.Length);
1
2736
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 anything. I would love some help, here is the code: import socket import thread import time
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.