| | |
Winsock Sending problem
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hey all,
I have this problem that I can't work out why it is doing it.
I've got a client - server program. The client sends an request to the Server, which in returns it queries an access database and save the output as a file. Which it will then send to the client.
It looks as if it saves the file correctly with out any corruption.
My problem is sometimes when I run it, some information gets corrupted (I think that it leaves some of the data off the end of the sending string)
Any suggestions on how to improve my code and make it more robust is extremly welcome
I've stripped out the code that I beleive is causing the problem. The code has some comments in it so you know why and what it is doing.
I have this problem that I can't work out why it is doing it.
I've got a client - server program. The client sends an request to the Server, which in returns it queries an access database and save the output as a file. Which it will then send to the client.
It looks as if it saves the file correctly with out any corruption.
My problem is sometimes when I run it, some information gets corrupted (I think that it leaves some of the data off the end of the sending string)
Any suggestions on how to improve my code and make it more robust is extremly welcome
I've stripped out the code that I beleive is causing the problem. The code has some comments in it so you know why and what it is doing.
•
•
•
•
Any suggestions on how to improve my code and make it more robust is extremly welcome
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
arrayNumber = Left(strData, InStr(1, strData, "\") - 1)
You're pulling an array number based on the position of the "\?"
I don't understand that. Explain, if you would.
And you declared arrayNumber as long and assign a string value to it? Why are you doing this? If you're using the Left() function (which returns a variant string value), you should be assigning its return value to a string variable?
I don't see how you dependably come up with a meaningful value number to use for your string array using this code.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
arrayNumber = Left(strData, InStr(1, strData, "\") - 1)
•
•
•
•
You're pulling an array number based on the position of the "\?"
I don't understand that. Explain, if you would.
•
•
•
•
And you declared arrayNumber as long and assign a string value to it? Why are you doing this? If you're using the Left() function (which returns a variant string value), you should be assigning its return value to a string variable?
I don't see how you dependably come up with a meaningful value number to use for your string array using this code.
(This is only an example)
A simple way of looking at that is that the server has 4 words to send "I have four words" I add it to an array
myArray(1) = I
myArray(2) = have
myArray(3) = four
myArray(4) = words
I then send each element of the array to the client
When the client gets the array element it saves it to an array, I do it this way in case I get the words mixed up when received, ie in this order "I four have words"
and that line makes sure that it is in the correct part of the array by taking the prefixed number and then saves the rest in to that element
Hope that makes sense
•
•
•
•
Hope that makes senseVisual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
arrayNumber = Left(strData, InStr(1, strData, "\") - 1)
I still can't make sense of that code. I still remember my old programming teacher telling me when I provided a very complex solution to a simple problem, "Keep it Simple Stupid!"
But this is what I'm guessing. You send a string: e.g. "1\some file data" You pull the number one with your code. That happens to be an integer. And I assume because there are only numbers before the "\" that you always extract integers in string form. And because the string can be converted by the compiler to a long, it doesn't throw an error.
In keeping with the paradigm of KISS--you did ask for tips for more robust code--I would simplify that code.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub SortNewData(ByVal StrSortcode As String, ByVal strData As String) ' Change that to the following Private Sub SortNewData(ByVal StrSortcode As String, ByVal strData As String, MyArrayNumber as Long)
If you already know what the ArrayNumber is, why not just send it?
Add another parameter to your function. And then you wouldn't have to write extra code to extract the file data either. Just send the data as a string without any extra identifying characters. You could eliminate about 2 or 3 lines of code in that one Select Case statement.
That would be simpler. And if you had to try to figure out 2 years from now what you were doing, it wouldn't be a problem.
A common problem with programmers is that they write complex solutions for simple problems. The code may seem impressive at the time, but all that complexity can lead to unintelligible and unmanageable code down the road. And that means spending extra unneeded hours to sort through solutions that should have been written simply to begin with. Extra hours translates into extra money. And that's not a good thing.
Sometimes our minds get trapped in 'complex' mode. We have to continually remind ourselves to keep it simple. The simpler the better.
I haven't had time to analyze the rest of the code. I was stuck there. But I assume your complex solution works, but why is the data corrupt? Put a breakpoint at that point and step through it with the F8 checking your variables as you go to see if you're program is processing the data correctly.
If you consistently come up with corrupt data in a certain situation, that provides a perfect condition to use a breakpoint and the F8 function key to step through that section of the code you believe to be at fault to check the data to see where the problem lies.
Sorry for the long delay
Your right about getting stuck in 'complex' mode, that was where my mind was on writing that blurb,
I only asked that as to make sure that I explained my self clearly, I know sometimes i don't ;S. The code it self is actually simple design,
Thanks for the tips, I'll merge them in.
The weird thing is that it works fine on my computer (hosting both server and client) but when I put the server on a different computer, it corrupts,
Any ideas?
Your right about getting stuck in 'complex' mode, that was where my mind was on writing that blurb,
I only asked that as to make sure that I explained my self clearly, I know sometimes i don't ;S. The code it self is actually simple design,
Thanks for the tips, I'll merge them in.
The weird thing is that it works fine on my computer (hosting both server and client) but when I put the server on a different computer, it corrupts,
Any ideas?
![]() |
Similar Threads
- Winsock C++ help: receiving data (C++)
- Winsock Multi-Client Servers (C++)
- TCP Port Close problem (C++)
- anyone can help me on my problem... (Visual Basic 4 / 5 / 6)
- WinSock problems. (C++)
- Data loss in Type Conversion. (C++)
- Winsock Problem (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: problem with INSERT INTO command
- Next Thread: Visual Basic 6 Sub programs?
Views: 611 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
6 429 2007 access activex add age append application basic beginner birth c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





