Solved

WINSOCK senddata query

Posted on 2007-11-22
2
920 Views
Last Modified: 2013-12-20
Hi, Hopefully someone who reads this will know straight away...

I have a server app and a client app. The serverapp recieves data using a TCP stream, and then executes the said data as an SQL statement on a database. The clientapp sends the SQL strings in plain text to the serverapp. This works like a charm, providing you do one statement at a time.

This is the clientapp code that sends the SQL statement (there is 15 lines or so that manipulate the string 'mysqlstring' before sending but its irrelevant):

For y = 1 To x
winsock.senddata(mysqlstring)
Next

Complicated, huh? Heres the problem: if x is 1, everything is perfect. Serverapp gets the stream and executes it OK. But, if x is anything above 1, it sends all the 'mysqlstrings' in the same TCP packet - so when my serverapp recieves the data, it trys to execute all the strings in one command - like "SELECT * FROM PRODUCT_DETAILSSELECT*FROM CUSTOMER_DETAILS" - which (unsuprisingly) it doesn't like and bombs out.

I can't use any kind of timer because this is to be used for performance testing (i.e. how many queries can it do in 60 seconds) so a timer would defeat the whole point.
I'm not willing to change any of the serverapp code to use a deliminator to seperate queries in the same packet.

My guess is that the cause is VB itself - it does all the crap itself (like handling TCP/IP) and because the winsock.senddata function gets called in such quick succession (mere milliseconds) it thinks "OK, I'll just send them all in one go".

Is this a correct understanding and does anyone know how to make it send the data immediatley when the function is called?


TY
0
Comment
Question by:pinkisthenewblue
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 80 total points
ID: 20339419
The "stacking" of data may or may not occur within VB itself.  It may actually happen along the way at any of the points where the data stops and gets passed along.  You do NOT have any control over this.  Even if you forced the data to move out of your app seperately, it could still get bottlenecked somewhere else along the way and become one bigger packet before it reaches its destination.

You said it yourself...

    "The serverapp recieves data using a TCP stream"

TCP is a STREAM...and this type of behaviour is INHERENT in the way TCP packets are handled by servers.  The ONLY way to properly handle this problem is to add some kind of "end of message" marker (typically a simple delimiter) so you can distinguish where one message stops and another begins.

I think you already knew exactly what needs to be done!  =\
0
 
LVL 2

Author Comment

by:pinkisthenewblue
ID: 20343438
I didn't realise TCP packets can get merged into one big packet - so even if I did manage to get it to send the data as and when I specify it would be futile anyway.

Truthfully I didn't want to re-code my server app because its written in vb.net and I struggle to get the basics working! I will start re-coding it.

Thanks for your reply.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now