473,511 Members | 15,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bytes sent but not receievd

5 New Member
Hi,

I need some ideas on where to start looking.

I have a client/server app I'm testing. Most of the work is done in the client. The server simply waits for a command then immediately sends a response, the server is a stub.

Both use the same NetworkStream for sending/receiving.

The client has 2 threads; the main thread and a second thread with a stream.Read() which waits for server responses. Client sends the first command (BIND) and immediately gets a response. 15 seconds later client sends second command (HEARTBEAT) and immediately gets a response. 15 seconds later client again sends HEARTBEAT. I can see the server sending the response but can't see it being received by client.

As there is nothing else going on and the client receives the first HEARTBEAT response what could possibly happen that stops it reading the second HEARTBEAT response?


Heres the line that the client hangs on...
Expand|Select|Wrap|Line Numbers
  1.   int bytesRead = networkStream.Read(buf, bufIndex, buf.Length - bufIndex);
  2.  
and heres the server that sends, receives
Expand|Select|Wrap|Line Numbers
  1. public void PduReceived(IPdu pdu)
  2. {
  3.   log.Debug("*** Received " + pdu);
  4.  
  5.   IPdu response = ...;
  6.   byte[] bs = response.GetBytes();
  7.  
  8.   log.Debug("Sending " + response + ", " + bs.Length + "bytes");
  9.   stream.Write(bs, 0, bs.Length);
  10.   stream.Flush();
  11. }
The streams/sockets are not adjusted anywhere.
Dec 8 '08 #1
5 2627
balabaster
797 Recognized Expert Contributor
Question: You say the data isn't received. I've had problems with something like this in the past where it wasn't that the data wasn't received but that I was missing it.

i.e.
Data was sent
Data should've been received
I start listening

Obviously this will never work. I had to adjust my application so that I started my listener thread which is used to process the incoming data and then fire off the data over the network stream. Only then could I receive.

If you're doing the send and receive on the same thread, there's a strong possibility you could actually miss the incoming data rather than it never showing up. It showed up, but you weren't paying attention when it arrived.

Not saying that is the issue, just throwing that thought out there...
Dec 8 '08 #2
TedTrippin
5 New Member
Thanks for the reply.

No, that isn't the problem. The client is a windows service and the server is a console app. The client receives the first 2 responses but not the third. I'm not messing with the threads/streams/sockets in between requests so I must have set something somewhere, but what?
Dec 8 '08 #3
balabaster
797 Recognized Expert Contributor
Is your listener getting hung up and missing the incoming data? What happens comment out the worker code and put a breakpoint on the receive? Do you get three responses then?

Have you used a tool like WireShark to verify that the data is being received at the network card and that it's being sent to the correct address?

If you can confirm that the data is sent to the right address and it's received by the network card at the hardware level then it's more likely your code. If it's not received at the hardware level and it was sent to the correct address then it's an issue somewhere on the network.

Don't assume that's it's your code... don't assume it's not your code either though. I usually find that the easiest way to debug these issues is right from the ground up. Debug what we know...

We know the data is being sent out by our service at the software (presentation) level.
Do we know it's being dispatched at the hardware level? WireShark should confirm that the network card is dispatching it to the correct address.
Do we know it's received at the hardware level at the destination? Again WireShark should confirm this.
If it's not received correctly, do we know the data is being transmitted over the network to the correct address? Router logs near the destination should confirm this.
Once we know that all this is present and correct, then we can assume there's an issue with our code... it could still be the network driver, but given that all your other network apps (presumably) are working correctly, this is unlikely.

By the time we've gone through these steps, we should be able to determine if the issue is with the sender or the receiver and it will pinpoint where we will most likely be effective in debugging our code.
Dec 8 '08 #4
TedTrippin
5 New Member
:(

I've been a complete numpty! I had a try catch around the client Read() and it was not reporting the exception!!!!

I had thought the problem was with the server cus that's what I was working on.
Dec 8 '08 #5
balabaster
797 Recognized Expert Contributor
LOL - it pays to have an open mind when it comes to debugging. Things aren't always as they first appear.

Glad you fixed it.
Dec 8 '08 #6

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

Similar topics

25
6633
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
1
1422
by: | last post by:
one thing to keep in mind is that i've written multiple tcp apps in .net 2002 and 2003, and haven't seen this problem before. I have a simple socket app where a client sends some # of bytes to...
13
2400
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record...
5
1146
by: iwdu15 | last post by:
hi, to get the bytes sent by a socket, in VB a simple local variable like below was used Dim recv as Byte() how can i do that in C++...this is what i am trying now Byte * rec = new Bytes; ...
20
5357
by: newbie | last post by:
Hi all, http://www.aswin.be/nictransfer.JPG How can I get these numbers with VB.NET ? I thought somewhere in WMI but I can't find them. Thank you, Aswin
5
3636
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
3
3760
by: Ricardo | last post by:
Can anyone help me to get the information given if you open the status box of your internet connection? It gives connection speed, duration, bytes sent, and bytes received.Is there some way to...
1
2407
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
5
5504
by: jaco.versfeld | last post by:
Hi There, I have a basic TCP client and TCP server in C++. The TCP client connects to the server, and after a setup phase starts to transmit a file to the TCP server using multiple packets...
0
7153
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...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
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...
0
5676
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,...
1
5077
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...
0
4743
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...
0
3230
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...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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...

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.