Results 1 to 13 of 13

Thread: [RESOLVED] Binary Data & .Net Sockets, {URGENT}{NO SOLUTION}{NO CHANCE}

  1. #1

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Resolved [RESOLVED] Binary Data & .Net Sockets, {URGENT}{NO SOLUTION}{NO CHANCE}

    Hello every one,

    After 2 hard week of work, finally i accomplished an reliable server and client classes which look like the VB Winsock, those 2 classes are reliable, also server enable multiple connections, as i test it accept 5000 connection and Handel them,

    When i try to create an demo app. on these 2 powerful classes, all goes fine, i faced an problem in sending files, as I'm using one channel only between server and client, i.e. each client have only one channel, this channel Handel both data and commands, we can distinguished between them, that command will always contain [#<CMD>#] tag before the command itself, so in the OnDataReceived event, we convert the byte array to ASCII string to search inside it, if we find the prev. tag then this a command else we just use that array to put on file or something, the logic is tested before on my prev. vb6 app.

    Here an scenario of connection,
    1- Client connected to server, server add its info to listview,
    2- Server request from client to capture desktop screen
    3- Client receive the command and capture the image convert it to JPEG, and then add to that array the following tag at the end of array [#<EOF>#], which help us to detect the end of file.
    4- Client tell the server that it ready to send, given to server the length of image array without the length of tag,
    5- When server receive readytosend, it the client socket info to helper class which contain the socket id, image size, and memory stream, which contain image chunks,
    6- then Server send the client an message ready to receive, in this moment client start sending data chunks in order of 1024 Byte per time,
    7- Every time server receive data it check if its EOF or not, if its, remove the EOF tag, and all nulls, and write the last chunk to the image,

    The problem is the image in coming deformed, also some times length of incoming data become greater than length saved from client in early steps, i.e. an **** on line collected while getting data,

    After hard work, i try to put an execution delayer, using Thread.Sleep(0), and the surprise that its finally work, and the image size is correctly, and image is nice, But all this in LAN, when test app on Wan all goes bad again, i think the problem not the delay, but delay here prevent some bad thing to happen, i want to know why server put extra data on the image stream, from where these extra data come, Am I Missing Something.?!?!?!??!?!?!?

    All i need, Any one test this code, its amazing, very exciting and commented, will learn you a lot, all i need is to detect the reason of that bugs,

    To know what I'm talking about, In the server side in the OnDataReceived even, try to comment the Thread.Sleep(0); and try to get an image, you will got ****, if you put that line again all goes fine, and if you put it, and test it on Wan it will cause problems again, So there is something wrong, and i don't know it

    Please any body help me finding that error.

    Here is the link of the code, its written using C# 2005.
    Source Code & Binary Files.

    Thanks every one and hope i explain the problem well, and hope for fast response.
    Thanks in advanced for whatever help.
    Attached Files Attached Files
    Last edited by Dominator; Feb 22nd, 2006 at 01:41 PM. Reason: Modify Attachment
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  2. #2

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, URGENT

    Hello,

    I'm sorry for repeating my request, but i'm stuck in that point, and unable to go on, as i test all tricks i know, Sockets are the underlay of my graduation project, which represent an primary component, so please if any body can test it, just run it an review its logic, may be somthing wrong i can't see,

    This will be greatfull,
    Thanks every one for helping.
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  3. #3

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Thumbs down Re: Binary Data & .Net Sockets, URGENT [WILL NEVER SOLVED]

    Now I'm sure, that the wrong in .Net socket,

    Cause no piece of code on the net able to send binary data, over WAN, i test as much as i found, but no one, deliver an correct package, I think that all these codes and people not wrong, the wrong in sockets library,

    .Net prove its failure, again, after slow and unstable development environment, here come the sockets, Microsoft Just Joking, they provide socket SDK, as an parts that need weeks from developers to get them on line, and start coding.



    IF THERE IS ANY BODY CAN PROVE THAT .NET SOCKET IS FUNCTIONAL I"M LISTENING...



    Thanks every one.
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    I guess I can prove that .NET sockets work fine. My applications work for me, one socket application I have has been platform tested and certified by VeriSign for Microsoft - there's no issues with it.

    Sockets are tricky and throw people off sometimes because they don't understand what's really going on. So, before you blame .NET...

    1) Do you have reliable code in another language that doesn't work the same in .NET?

    2) There's no way I'm looking at a huge project and try to debug it for you. Can you provide a small, simple, code block that illustrates the problem you're having?

    Mike

  5. #5

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Unhappy Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    I will be very greatfull, if you can prove this, I love to be wronge,
    I'm sorry every one, if i was somthing not good, but really i'm depressed, because after 4 weeks of coding and tests, nothing works, and i don't know why, where is the error, I try every piece of code on the net, but no luck, no code can provide an correct package,

    I hope i finde the error,
    I blame Microsoft cause of IDE, its buggy,

    About your first comment, I don't got what you mean!!, But as i understand, i have an very reliable VB, Winsock code, and i builde a lot of projects in past using VB, but now a days we in Managed Era, so .Net socket is the only way, Some time i feel that Socket API is eaiser than .Net Socket, specially threading, But all these issue are solved in my first post code, which handel all thread safe issue,

    The problem as you will see is the data,
    I attached an very abstract code, which use the generic Server-Client classes, i removed any controls on form and thread safe stuff, to make it easer to debug, client will send an file to server which will write it,

    To feel where is the problem,
    At server side, At DataReceived event, at last line,
    Remove the Delayer line, Thread.sleep.
    And try to send an jpg image, test it many time, you will got an deformed image, somtime, you got nothing, when you put that line again it works fine

    On WAN, never work....

    If you can provide help i will be greatfull, And i hope you prove that i'm wrong.
    Thanks every one for reading and Help...
    Attached Files Attached Files
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  6. #6

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    Hello Developer,
    Is there is any reliable .Net socket class, that can send an binary file over LAN & WAN,

    They said that .Net socket is ok, However i can't get it work,
    So any suggestion on how to make it work, Or any guide to a working class.

    Thanks for help.
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  7. #7
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    I've worked with sockets before .NET, but I haven't worked with .NET sockets. They are tricky to keep uncorrupted. I have looked briefly at your code but there's nothing obvious. I don't have Visual Studio 2005 so I can't recompile it easily. My suggestion for you is to write a new stripped down version of your app. None of the fancy object-orientation and event raising stuff. Just down and dirty get the sockets to connect and send some data. That way you can step through the code easier. Also, send simple text files, instead of jpeg files, and print the incoming data out on the screen or in the immediates window so you can see exactly what and when stuff is coming in off the socket.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  8. #8

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    Thanks for your replay.

    I will follow your advice, thanks.
    About sending small text file instead of large image, I did, If we decide that our buffer is 1024, So 1024 byte will collected from stream, may be it contain nulls, so we resize that array with the original file size, so we remove that nulls,

    If we sent an file of size 2000, then we collect from stream 2048, then we reszie that array to be its original size -> 2000,

    When i try to send 1 KB, its work, However, more than that, packets come deformed,


    An somthing i noticed, Is that the InDataReceived, CallBack, i didn't use the lock technique, so may be another threads access it, and write an garbish??

    I don't Know, but also after i use Lock, to prevent dead lock, also Data become deformed....

    I NEED HELP, I don't know why Its too hard...
    Socket class it self, is easy, however its not work!?!?!?

    You said, its looks ok, But its not..., Why i don't know

    I will be very greatfull, if any one provide an reliable examble that able to send data over WAN..

    Thanks for helping me..
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  9. #9
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    Can you explain further how you remove null characters and replace them? I am thinking that that's not such a good idea when working with binary files. For example, if you look at this attatched image of a JPG in a hex editor, you can see all the null values scattered throughout the image.. and this is just in the header!

    Bill
    Attached Images Attached Images  
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  10. #10

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    You miss understand me,
    As an example if we have 1.4 KB file, we send this file on chunks,
    These chunks will be of size 1024 bytes, as an examble,
    We will get these chunks and put it into our file, even the nulls, and any extra or grabish,

    After this, we will resize the file to be the original file size, by this way, Nulls and garbish from stream will be eliminated, i.e.
    The good chunks should be between 0 and the LOF, so any other chunks after the EOF, will considerd as garbish, so the finall array will be resied with LOF, and this result, the Good chunks.

    Hope you got me.
    Help!
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  11. #11
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    I think I found something. If you look up the FileMode enumeration, OpenOrCreate does partially what you want except it doesn't seek to the end of the file. Meaning each new chunk of data would overwrite the last. Not sure if that's whats really going on since you said you get more data on the server side then you sent from the client. I believe what you want there is FileMode.Append, which will create the file if it doesn't exist, or open it and start the writing at the end.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  12. #12

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, URGENT [[WILL NEVER SOLVED]]

    Thanks for your effort,.
    I will keep that in minde, I don't know, how i did that
    Any way, I test it, and problem still, and by the way, in my case i will not write to file i will use memory stream.

    But its good point...
    Thanks a lot, for your help...

    Dose we need lock(), inside the OnDatareceived??!?!, I test it but no diff.
    I though, that threads, can use the same function at same time, so lead to garbish, but may be i locked the wrong object...

    Help!!
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

  13. #13

    Thread Starter
    Lively Member Dominator's Avatar
    Join Date
    Oct 2004
    Location
    Egypt
    Posts
    65

    Re: Binary Data & .Net Sockets, {URGENT}{NO SOLUTION}{NO CHANCE}

    Finally i got the solution,
    the problem was that i use a buffer of 1024, so when data coming may be its fill the whole 1024 buffer, i.e. it may contain nulls after the real data, this is the bug, I solve this by using the EndReceive async call to tell me what exact bytes received, so i get those bytes only from the buffer and eliminate nulls, Thanks to Mike woodring he support me a lot.

    Thanks a lot for every one comment, and the help i got
    .........................................................
    John F. Gouda {A.K.A}{Dominator Legend}
    Software Engineer
    +20-0125113313
    .......................................................
    Please feel free to download my projects:
    Http://DominatorLegend.Co.Nr
    .................................................................................................... ................................................................................................
    Direct Library | Speech Library | System Locker V.3 | Magic Encryptor | And many many more, follow the link above...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width