Solved

VB6: Winsock Trivia Game Problem

Posted on 2004-09-28
2
628 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
ID: 12175048
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
ID: 12186330
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I lock down a trademark? 11 77
FBX SDK with Unreal Engine 4. 5 378
Computer use secret parental monitoring 14 94
Upgrade PC processor to i7 - 3d Game dev 3 74
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…
As we all know Counter Strike is a very popular computer game. Usually it is played over a network for which people create a server and users join it but it is interesting to know that one can creates a dedicated server which not only hosts the game…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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