473,785 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wierd error in sending data via TCP

Hi,

I've a service that connects to the clients via TCP and sends data on
client's opened TCP port. The data is in XML and I use ASCII encoding. There
is 8 byte of header containing length of data in text appended to the TCP
payload. So, if 1260 bytes of data needs to be sent, the header pre-pended
is 00001260 and total 1268 bytes is sent.

It works fine on my developoment and test system. Until on another system
sometimes the 8 bytes of header is NOT received correctly by clients.
Sometimes it is 001260 or sometimes there are some garbage characters in
front of the length xxxx5268. Ethereal trace shows the same thing. But the
service log shows that the data was sent successfully.

Here is the service sample code used to send data to the connected client:

private bool Send(string strXML)
{

int ret = 0;

strXML= strXML.Replace( "utf-16","UTF-8");

int len = strXML.Length;

string header = len.ToString("0 0000000");

string strTotalData = string.Format(" {0}{1}", header, str);

ASCIIEncoding asen = new ASCIIEncoding() ;

byte[] ba = asen.GetBytes(s trTotalData);

try

{

Monitor.Enter(t his);

{

ret = m_Socket.Send(b a);

if ( ret != 0 )

LogAdv("Sent " + ret + " bytes so far !", false);

}

}

catch(Exception ex)

{

Misc.Globals.Lo gError(GetName( ),"Error in sending to " + m_strChannelNam e +
"!" + ex.ToString(), ref m_EventLogger);

m_strErrorMsg = ex.Message;

return false;

}

finally

{

Monitor.Exit(th is);

}

return true;

}

Anything wrong with this ?

Any advice appreciated!!!

Thanks in advance and regards

Navin


Nov 22 '05 #1
0 1058

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1087
by: Matthew Lavinder | last post by:
I have a crazy problem. I am trying to send email through a server that requires SMTP authentications. So I downloaded PHPMailer. I copied over the class file and sample code and ran a test. I received a timeout error. Oh if it only ended there. I am using PHP Designer 2005 so I decided to run it through the debugger. IT WORKED PERFECTLY. Went back to the page using my browser, and again, I received the timeout error. I downloaded...
9
3226
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on CDOmail. I don't want to use the Outlook reference because outlook prompts each time program access it and I have found a way to disable that. Can I use webmail with exchange? Thanks
8
1334
by: Steve | last post by:
Hi all, I had a strange crash this morning with an app I've been working on. I just clicked the main menu bar and got an OutOfMemory exception, with a message of something like "unable to get info to create bitmap". (not the correct wording but I was in a hurry and didn't think to copy/paste it somewhere). The app is just a basic winforms app and it was not "doing" anything at the time. ie no threads running, not working on...
13
10147
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the parent table. ----------------------------
1
1576
by: JamesB | last post by:
Hello I am in the process of making a small app that will be used by the slightly more, er, IT challenged customers we have to send us their databases via FTP. Going ok, but when I come to writing the data stream it is terminating with "unable to write data to the transport connection tcpclient" Adding a quick messagebox on the exception, I am getting: "An established connection was aborted by the software in your host machine".
7
9538
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. The .NET 2.0 exception does give a little more info than .NET 1.1 did, but not much. Can anybody give any pointers about how to track this down? It occurs every 10 hrs around the clock, like clockwork. I have included the stack trace, but...
3
1551
by: Tom | last post by:
We are experiencing some wierd debugging behavior. What happens is that, during debugging with VS 2003, the debugger seems to 'skip' statements that are associated with database operations. For instance, I can be single-stepping through a VB.NET program, and once I hit a DB related statement (such as setting command parameters, executing a data reader, etc) the debugger will simply 'skip' ahead a number of statements (if not all the way to...
5
1720
by: desktop | last post by:
I am confused about the use of the template parameter "E" in the below class. Since when is it allowed to use these parameters like "E(1)" and what does it mean (where can I read more about this kind of use)? template <typename E> class Mytest { public: Mytest(int n) { s = E(0);
1
2758
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is used. If this file is given to someone with some other current codepage, the file is not displayed correctly. Simply converting the file to Unicode will make the data display properly. When performing the encoding process the encoding will escape...
0
9645
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
10341
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
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
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
5383
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...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.