Solved

VB6: Winsock Trivia Game Problem

Posted on 2004-09-28
2
632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Joseph
CONTENTS I.      What is a MOBA?   a. Definition   b. Origin   c. Current Generation II. The New Games   a. League of Legends   b. Heroes of Newerth   c. Dota 2   d. Smite III. Comparison IV. Conclusion ------------------------…
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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