Solved

WINSOCK senddata query

Posted on 2007-11-22
2
917 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 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

8 Experts available now in Live!

Get 1:1 Help Now