Solved

VB6: Winsock Trivia Game Problem

Posted on 2004-09-28
2
623 Views
Last Modified: 2013-11-12
i made a trivia game for a friend. basically, the server sends questions to all the clients and who ever answers them first, gets a point. the problem is, sometimes winsock sends data a the same time. also, when the client disconnects, then tries to reconnect again, the server gets an error. i dont want to use "on error resume next" because that sometimes causes complications. is there any way to fix this winsock problem?

my code for sending data is

for a = 1 to wsk.ubound
  if wsk(a).state = sckconnected then
    wsk(a).senddata strData
  end if
next a

now, it send the data correctly, but sometimes it sends them at the same time, and the String gets combined together.

------------------------------------------
Sub 1:
strData = "Chat///Goodbye World"
for a = 1 to wsk.ubound
  if wsk(a).state = sckconnected then
    wsk(a).senddata strData
  end if
next a

Sub 2:
strdata = "Com///Hello world"
for a = 1 to wsk.ubound
  if wsk(a).state = sckconnected then
    wsk(a).senddata strData
  end if
next a
------------------------------------------

when the client receives the data, it gets this:
"Chat///Goodbye WorldCom///Hello World".

could someone please help? if someone needs the source for both client and server, i would upload somewhere. thank you!
0
Comment
Question by:Gamemaster328
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
Comment Utility
Hi Gamemaster328,

What you need to do is create an end of message marker.  It looks you are using /// as a parameter delimiter which is a great start.  You need to the same thing for the end of a message so you you know when you have received a partial, entire or multiple messages in on DaraArrival event.

Below is a link to a chat system that demonstrates the idea.  In it I have used Chr(0) as a parameter delimeter and Chr(1) as a command delimeter.  Study the DataArrival() and processInputs() subroutines carefully.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20870693.html

Regards,

Idle_Mind
0
 

Author Comment

by:Gamemaster328
Comment Utility
wow. that was amazing! it worked well. thank you. i changed /// to chr(1) and the end delimiter to chr(5) i havn't tested what all chr()s are, but im pretty sure i will be using more and more of the chr functions. =) thank you!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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