willa2
asked on
Winsock Buffering
I am making a little version of pong, but enabling it for the net. They way I have made the net code is that every time your paddle is moved, the GetData method of Winsock is called, sending the paddles Top property to the server. The problem I have is that the server recieves several values at once, like 200 200 200 200 220 220 220. When what I want is that on data arrival to be is that it recieves 200 by itself and then 220 in a seperate arrival. Instead, Winsock seems to buffer the values being sent together. What I have done to get round is to take the first value from this string and use that, the problem with this is that the movement is very jumpy. What I am after is two simple programs, one a server program and one a client program. I want the programs to connect and when the up key or down key is pressed on the client program, the block moves and sends its position to the server through the Winsock, and the block on the server side moves SMOOTHLY. Anything similar to this will be fine.
ASKER
Well I was wondering if it would be possible to use DirectX, as I have been reading about how it can use DirectPlay to make net connections
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw, open the listening form before attempting to connect :)
Ok you know the size of the packets coming back from the socket whay don't you just parse the packets out it will make things a lot smoother for you.
As an example
Your data arrival from the winsock is a asynchronous i.e can happen at any time.
Add a timer to your program.
Create a public collection for your values (this will form queue for the data).
Add a function Parse
'This will be a recursive call
Function Parse(strInput as String) as boolean
Dim strTemp1 as String
Dim strTemp2 as String
strTemp1 = Mid(strInput,1,3)
colData.Add strTemp1
strTemp2 = Mid(strInput,4)
if Len(strTemp2) > 3 then
end Function
As an example
Your data arrival from the winsock is a asynchronous i.e can happen at any time.
Add a timer to your program.
Create a public collection for your values (this will form queue for the data).
Add a function Parse
'This will be a recursive call
Function Parse(strInput as String) as boolean
Dim strTemp1 as String
Dim strTemp2 as String
strTemp1 = Mid(strInput,1,3)
colData.Add strTemp1
strTemp2 = Mid(strInput,4)
if Len(strTemp2) > 3 then
end Function
Ok you know the size of the packets coming back from the socket whay don't you just parse the packets out it will make things a lot smoother for you.
As an example
Your data arrival from the winsock is a asynchronous i.e can happen at any time.
Add a timer to your program.
Create a public collection for your values (this will form queue for the data).
Add a function Parse
'This will be a recursive call
Sub Parse(strInput as String)
Dim strTemp1 as String
Dim strTemp2 as String
strTemp1 = Mid(strInput,1,3)
colData.Add strTemp1
strTemp2 = Mid(strInput,4)
if Len(strTemp2) > 3 then
Parse(strTemp2)
end if
end Function
When data arrives from the socket call this Sub on the data it will add the data to your queue.
Now you need to pull the data off the queue you can do this on a FIFO basis from your program.
You can do this in your timer control or wherever you were originally calling your movement code from.
strData = colData.Item(1)
colData.Remove(1)
strData is the piece of data you want to work with.
This means your data will be arriving as quickly as possible and you should get a nice smooth movement.
Vin.
As an example
Your data arrival from the winsock is a asynchronous i.e can happen at any time.
Add a timer to your program.
Create a public collection for your values (this will form queue for the data).
Add a function Parse
'This will be a recursive call
Sub Parse(strInput as String)
Dim strTemp1 as String
Dim strTemp2 as String
strTemp1 = Mid(strInput,1,3)
colData.Add strTemp1
strTemp2 = Mid(strInput,4)
if Len(strTemp2) > 3 then
Parse(strTemp2)
end if
end Function
When data arrives from the socket call this Sub on the data it will add the data to your queue.
Now you need to pull the data off the queue you can do this on a FIFO basis from your program.
You can do this in your timer control or wherever you were originally calling your movement code from.
strData = colData.Item(1)
colData.Remove(1)
strData is the piece of data you want to work with.
This means your data will be arriving as quickly as possible and you should get a nice smooth movement.
Vin.
You could also delimit your data transmission with a , at the end of each packet you send i.e. Winsock1.Send "200,"
and use Split to parse the packets. Using this you can transmit 200,2500,3000, etc.
e.g
Sub Parse(strTemp)
Dim strValues()
strValues = Split(strTemp, ",")
for each strVal in strValues
if strVal <> "" 'If each value is delimited with "," then you will get a blank one at the end of the array
colData.Add strVal
end if
next strVal
end sub
Vin.
and use Split to parse the packets. Using this you can transmit 200,2500,3000, etc.
e.g
Sub Parse(strTemp)
Dim strValues()
strValues = Split(strTemp, ",")
for each strVal in strValues
if strVal <> "" 'If each value is delimited with "," then you will get a blank one at the end of the array
colData.Add strVal
end if
next strVal
end sub
Vin.
Hi willa2,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Split points between: wpsjr1 and VincentLawlor@devx
willa2, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Split points between: wpsjr1 and VincentLawlor@devx
willa2, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Per recommendation, force-accepted.
Netminder
CS Moderator
VincentLawlor: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328906
Netminder
CS Moderator
VincentLawlor: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328906
Const TCP_NODELAY = 1