Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sockets overflowing?

Sockets overflowing?

Scheduled Pinned Locked Moved C#
databasesysadminxmlquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hammerstein05
    wrote on last edited by
    #1

    I've created an application that sends images along with some other information in an XML message from a handheld device to a server running on my pc. There are 14 records in the database I'm processing on the handheld, and the first four images and information come up just fine. Then things start to go wrong. As far as I can see in my log file, everything is overrwriting, my logfile stops making sense and new lines seem to be everywhere. Basically, I have a class for creating my XML message, with the AddImage method as below; public bool AddImage( string tagname, string ImageFile ) { bool Result = false; try { FileInfo ImageInfo = new FileInfo( ImageFile ); int ImageSize = Convert.ToInt32( ImageInfo.Length); using (FileStream SaveImage = new FileStream( ImageFile, FileMode.Open, FileAccess.Read, FileShare.None )) { byte[] ImageData = new byte[ImageSize]; int BytesRead = SaveImage.Read( ImageData, 0, ImageSize ); xmlMessagePacket.Append( "<" + tagname + ">" + Convert.ToBase64String( ImageData, 0, BytesRead) + "" ); } Result = true; } catch (Exception gExc) { errorState = gExc.Message + " / " + gExc.StackTrace; } return Result; } I add the fields in, and the first four messages work fine, but after that the application hangs. Can anybody suggest what I should look at first? Could it be that I'm overloading my socket somehow.

    M L K 3 Replies Last reply
    0
    • H hammerstein05

      I've created an application that sends images along with some other information in an XML message from a handheld device to a server running on my pc. There are 14 records in the database I'm processing on the handheld, and the first four images and information come up just fine. Then things start to go wrong. As far as I can see in my log file, everything is overrwriting, my logfile stops making sense and new lines seem to be everywhere. Basically, I have a class for creating my XML message, with the AddImage method as below; public bool AddImage( string tagname, string ImageFile ) { bool Result = false; try { FileInfo ImageInfo = new FileInfo( ImageFile ); int ImageSize = Convert.ToInt32( ImageInfo.Length); using (FileStream SaveImage = new FileStream( ImageFile, FileMode.Open, FileAccess.Read, FileShare.None )) { byte[] ImageData = new byte[ImageSize]; int BytesRead = SaveImage.Read( ImageData, 0, ImageSize ); xmlMessagePacket.Append( "<" + tagname + ">" + Convert.ToBase64String( ImageData, 0, BytesRead) + "" ); } Result = true; } catch (Exception gExc) { errorState = gExc.Message + " / " + gExc.StackTrace; } return Result; } I add the fields in, and the first four messages work fine, but after that the application hangs. Can anybody suggest what I should look at first? Could it be that I'm overloading my socket somehow.

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Maybe you have too make sure, that the method isn't called again bevor the last job has finished. Maybe the "Mutex" class can help you. http://msdn2.microsoft.com/en-us/library/system.threading.mutex.aspx[^] Hope that helps you. All the best, Martin

      H 1 Reply Last reply
      0
      • M Martin 0

        Hello, Maybe you have too make sure, that the method isn't called again bevor the last job has finished. Maybe the "Mutex" class can help you. http://msdn2.microsoft.com/en-us/library/system.threading.mutex.aspx[^] Hope that helps you. All the best, Martin

        H Offline
        H Offline
        hammerstein05
        wrote on last edited by
        #3

        Thanks for that, but I'm not entirely certain that is the problem. Basically, when I send a message, I set a loop going; while(!MessageReturned) Application.DoEvents( ); so I can't send the next message until my event fires with the return of my previous message. According to my logfiles, the application thinks it is able to send several more messages after the one that causes it to fail. Very confusing.

        1 Reply Last reply
        0
        • H hammerstein05

          I've created an application that sends images along with some other information in an XML message from a handheld device to a server running on my pc. There are 14 records in the database I'm processing on the handheld, and the first four images and information come up just fine. Then things start to go wrong. As far as I can see in my log file, everything is overrwriting, my logfile stops making sense and new lines seem to be everywhere. Basically, I have a class for creating my XML message, with the AddImage method as below; public bool AddImage( string tagname, string ImageFile ) { bool Result = false; try { FileInfo ImageInfo = new FileInfo( ImageFile ); int ImageSize = Convert.ToInt32( ImageInfo.Length); using (FileStream SaveImage = new FileStream( ImageFile, FileMode.Open, FileAccess.Read, FileShare.None )) { byte[] ImageData = new byte[ImageSize]; int BytesRead = SaveImage.Read( ImageData, 0, ImageSize ); xmlMessagePacket.Append( "<" + tagname + ">" + Convert.ToBase64String( ImageData, 0, BytesRead) + "" ); } Result = true; } catch (Exception gExc) { errorState = gExc.Message + " / " + gExc.StackTrace; } return Result; } I add the fields in, and the first four messages work fine, but after that the application hangs. Can anybody suggest what I should look at first? Could it be that I'm overloading my socket somehow.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          hammerstein05 wrote:

          Could it be that I'm overloading my socket somehow

          I don't even know what that is supposed to mean but I doubt that is the problem. Based on what you posted it is far more likely that you have a bug in your protocol and/or implementation of the protocol.

          led mike

          1 Reply Last reply
          0
          • H hammerstein05

            I've created an application that sends images along with some other information in an XML message from a handheld device to a server running on my pc. There are 14 records in the database I'm processing on the handheld, and the first four images and information come up just fine. Then things start to go wrong. As far as I can see in my log file, everything is overrwriting, my logfile stops making sense and new lines seem to be everywhere. Basically, I have a class for creating my XML message, with the AddImage method as below; public bool AddImage( string tagname, string ImageFile ) { bool Result = false; try { FileInfo ImageInfo = new FileInfo( ImageFile ); int ImageSize = Convert.ToInt32( ImageInfo.Length); using (FileStream SaveImage = new FileStream( ImageFile, FileMode.Open, FileAccess.Read, FileShare.None )) { byte[] ImageData = new byte[ImageSize]; int BytesRead = SaveImage.Read( ImageData, 0, ImageSize ); xmlMessagePacket.Append( "<" + tagname + ">" + Convert.ToBase64String( ImageData, 0, BytesRead) + "" ); } Result = true; } catch (Exception gExc) { errorState = gExc.Message + " / " + gExc.StackTrace; } return Result; } I add the fields in, and the first four messages work fine, but after that the application hangs. Can anybody suggest what I should look at first? Could it be that I'm overloading my socket somehow.

            K Offline
            K Offline
            Kythen
            wrote on last edited by
            #5

            Does the apparent lack of a closing tag in your XML message make any difference in how the code behaves? That's the only obvious thing I can spot. Have you run the code in a debugger to see where exactly the code is hanging up?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups