Sockets overflowing?
-
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. -
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.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
-
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
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.
-
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.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
-
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.