Question

C# socket app stop working when receiving page break

Asked by: ryankahan

Hi Guys,

My developer has written an C# app/service that needs to connect via TCP/IP to an IP and port on a PBX to collect CDR (call data record) data and pipe it to a sql2005 table.
We collected sample raw CDR (see attached) from the PBX (Samsung 7200) using Putty and replay it (to simulate) through SocketWorkbench, then the app works fine and does not fail.
When trying the app onsite connecting directly to the actual IP and port of the PBX, the app fails when a heading/empty-row of data is received and stops receiving/processing any new data that the PBX makes available. THIS IS OUR PROBLEM AND CANNOT SEEM TO SEE WHY.  HELP!!!!
On another site using the same app. We connected to another PBX (Mitel 3300) also to a IP and port where the raw CDR data (see attached) does not have any headings/empty-rows, the app runs fine and does what it is suppose to without fail.

Please help!

Thanks again in advance.

Hannes.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-12-10 at 22:40:53ID23975235
Tags

Microsoft

,

C#

,

VS C# & VSS2008

Topics

C# Programming Language

,

Winsock

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CDR in DOS and CDR quality
    Hi, I've a GoldStar CD-rom and a CDR Panasonic CW-7582-B. I want to know if it's possible to use the CDR to read stuff in DOS. If it's possible, where can I get the driver since it comes with none. Also, my CD-rom has trouble reading some CDs that I burned lately, some par...
  2. Win98 won't assign drive letter to CDR
    I just loading Win98 on my computer. I have two cd roms. A 24x memorex set as primary and a CDR set as a slave. Win98 loads the drivers and says it is working correctly, except it won't assign it a drive letter so I can use it. The CDR is a 7100 from HP.
  3. Socket
    I am connecting to socket at backet using Socket class here. Its getting connected and taking data from it. But if the server socket is killed or having any problems to talk with my socket..how can i know and pop up a message? Here my socket is simply waiting for response and...
  4. DVDX /DVD TO CDR
    I USE DVDX A PROGRAM THAT BURNS A MOVIE ON YOUR HARD DRIVE. WE USE WINDOWS 98,AND I MADE A MOVIE ON A CDR 80 MIN.IT TOOK 2/1/2 CDRS. IS THERE AN EASIER WAY TO DO THIS OR A PROGRAM I CAN GET ,OR A LONGER CDR I TRIED THE DVDS BLANKS THAT HOLD 4.6 GIG,BUT THESE WONT WORK PLEASE ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: SunnyDarkPosted on 2008-12-10 at 23:56:09ID: 23146462

This might be  not a problem with the TCP comunication but a problem in the code that is processing the data.
Without you , posting the code it is hard to tell.
In order for us to be able to help you we need to see the part in the code that is processing the data.

 

by: ryankahanPosted on 2008-12-10 at 23:57:45ID: 23146467

Sure.
I will get my guys to give the the code extract and I'll post soonest.

 

by: DropZonePosted on 2008-12-11 at 10:42:28ID: 23150974

I agree with SunnyDark, it seems to be a problem with the service.  It most likely was not made to expect empty rows and it chokes when encountering one.

Post the code and we'll see what we can do.

     -dZ.

 

by: ryankahanPosted on 2008-12-11 at 12:34:09ID: 23151947

Here is my guys code:

                TcpClient client = new TcpClient(ServerIP, ServerPort);

                if (client.Connected)

                {

                    //Get the SMDR

                    NetworkStream network = client.GetStream();

                    StreamReader SMDRReader = new StreamReader(network);

                    string SMDR = "";//SMDRReader.ReadLine();

                    //SMDR = SMDRReader.ReadLine();

                    //ProcessSMDR(SMDR);





                    while ((SMDR = SMDRReader.ReadLine()) != null)

                    {



                        //Check if there is data to save

                        if (SMDR.Trim() != String.Empty)

                            ProcessSMDR(SMDR);



                        SMDR = "";

                       

                       



                    }

                }

 

by: DropZonePosted on 2008-12-11 at 13:28:46ID: 23152531

I do not see a problem with that code.  I do see that the files have different formats.  Particularly, there seems to be an inconsistency with the line terminators.  The 3300 file ends the lines with CR-BACKSLASH-LF, while the 7200 file ends the lines with BACKSLASH-LF-BACKSLASH-LF.

Could it be a transport problem, where the line terminators are being mangled?

      -dZ.

 

by: ryankahanPosted on 2008-12-11 at 13:50:48ID: 23152764

I'll forward you commented to my guys and revert.
Thanks.

 

by: SunnyDarkPosted on 2008-12-11 at 15:10:47ID: 23153435

Try changing:
while ((SMDR = SMDRReader.ReadLine()) != null)

                    {



                        //Check if there is data to save

                        if (SMDR.Trim() != String.Empty)

                            ProcessSMDR(SMDR);



                        SMDR = "";

                       

                       



                    }
To:

                    while (network.DataAvailable )
                    {
                        SMDR = SMDRReader.ReadLine();
                        if (SMDR == null) continue;
                        //Check if there is data to save
                        if (SMDR.Trim() != String.Empty)
                            ProcessSMDR(SMDR);
                    }
                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: ryankahanPosted on 2008-12-11 at 21:53:16ID: 23155221

Thanks.
We'll try it ASAP.

 

by: SunnyDarkPosted on 2008-12-14 at 05:39:24ID: 23167630

Good luck.

 

by: ryankahanPosted on 2008-12-15 at 04:42:10ID: 23172745

Hi Guys,

Seems that our problem has elevated itself into another dimension or something similar.
Okay, let me try explain ... we have managed to establish that we do NOT have a connection or connection-state problem from the service to the PBX IP+port, as we added extra code that we can see that when CDR is given off by the PBX by being recognized by the service and a entry created in the sql table.
What we still have issue with, is when the service/app is started the very first string of CDR is captured correctly, but all the CDR strings after that is being recognized (row created in the table), but the data/message field is just empty.
We also noticed that we get an error returned when trying to INSERT data into the MESSAGE field saying that our strings longer than 4000 characters (which is the limit for this field).
Another suspect issue is that the 'empty strings' are actually not empty, but when doing a character count on the empty strings, that can vary between 80 to 100s of characters in length which is just empty spaces ... it seems.
My take on this at the moment is that we are getting an END OF LINE identifier or CARRIAGE RETURN, but out code cannot interpret the character or command issued.

Your help & comments please?

Thank you.

Hannes,

 

by: SunnyDarkPosted on 2008-12-15 at 06:09:32ID: 23173390

My suggestion is that you implement your own parser for the feed...
That is just read the data as character stream  directly from NetworkStream into a buffer. Then parse it yourself in code .

 

by: DropZonePosted on 2008-12-15 at 06:26:23ID: 23173551

One more thing I'd like to add is that you should make sure that the format of the files, as you are storing them, is correct; that no transport level translations are occuring to newline delimiters and such.

As for parsing the lines, I concur with SunnyDark.  The StreamReader.ReadLine() method expects either a line-feed (\n) or a carriage-return + line-feed (\r\n) delimiter, and your files have various sequences that may be affecting the reader.

     -dZ.

 

by: ryankahanPosted on 2008-12-17 at 00:40:18ID: 23191581

Hi Guys,

I want to do a simple test to see if I have the same issue, for when my service is receiving the data instead of requesting the data.
I am searching the web for a utility to test with that will allow me to connect to an IP+port and forward onto an IP+port (my service).  I managed to find a lot of port forwarders, but only listeners, not the one I need.
I'd appreciate if you ca recommend something.

Thank you.

Hannes.

 

by: DropZonePosted on 2008-12-17 at 03:07:44ID: 23192169

Are you looking for a network sniffer to look at the TCP transaction while it's happening?  If so, then I recommend WireShark.  It can analyse TCP communications by protocol and let you view what is going on.

        http://www.wireshark.org/

        dZ.

 

by: ryankahanPosted on 2008-12-17 at 05:05:30ID: 23192815

Hi dZ,
NO, I am not trying to sniff the data, but I need to be able to connect to an IP+port (similar to a telnet connection) AND also be able to forward the data that is received/collect to another IP+port.
I managed to find a lot of utils to listen on a local port and forward to an IP+port, but I need to connect to an IP+port first to get my data and not just listen on a port.

I hope this explains this?!?!?!

Thanks.

Hannes.

 

by: DropZonePosted on 2008-12-17 at 06:01:10ID: 23193223

If I understand correctly, what you want to do is open a connection to a remote IP, retrieve data, then open another connection to a separate host and transmit the data from one to the other.  Off hand, I do not know of any tool that does this.  You could build your own, I suppose.

What are you trying to accomplish with this, and how does it relate to your problem?

    -dZ.

 

by: SunnyDarkPosted on 2008-12-17 at 07:18:37ID: 23194058

There is no difference if you are retrieving the data or receiving it, since you have no control on what happens on the other end (I suppose). So If you are trying to solve your problem with the format of the string I strongly suggest that you implement your own parser for the data...

TcpClient client = new TcpClient(ServerIP, ServerPort);
if (client.Connected)
{
    NetworkStream network = client.GetStream();
    if (network.CanRead)
    {
        byte[] myReadBuffer = new byte[1024];
        StringBuilder SMDR = new StringBuilder();
        int numberOfBytesRead = 0;
        // Incoming message may be larger than the buffer size.
        do
        {
            numberOfBytesRead = network.Read(myReadBuffer, 0, myReadBuffer.Length);
            int index = 0;
            int count;
            for (int i = 0; i < numberOfBytesRead; i++)
            {
                // implement your own matching patterns...
                if (myReadBuffer[i] == '\r')
                {
                    SMDR.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, index, i - index));
                    ProcessSMDR(SMDR);
                    SMDR = new StringBuilder();
                }
                if (myReadBuffer[i] == '\n') index++;
            }
            if (index < numberOfBytesRead - 1)
            {
                SMDR.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, index, numberOfBytesRead - index));
            }
        }
        while (network.DataAvailable);
    }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: DropZonePosted on 2008-12-18 at 03:21:47ID: 23202272

I see that you accepted my answer.  I also see that you gave it a "B", implying that it didn't really solve your problem.  Can you tell us how it was solved, or if you are still having problems?

      -dZ.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...