Sending the data

vampire
04-30-2003, 01:50 PM
Hi there,

I've been doing a small winsock game for multiple clients and I've got this problem with sending data to all the clients. Guess the data is being send way too fast ...

for example :

Player 1 connects and receives
NEW_PLAYER : [1] (5,8)

-> no problem

Player 2 connects and should receive the positions from all other users. What he receives :
NEW_PLAYER : [1] (5,8)NEW_PLAYER : [2] (1,1)

Conclusion : everything is being send to him, that's not the problem, but it should be send one by one tho ...

I do it with this code :


For i = 1 To ConId
DoEvents
sckPlayer(i).SendData "NEW_PLAYER : [" & conid & "] (" & Mypos(conid).X & ", " & Mypos(conid).Y & ")"
DoEvents
Next


I thaught "DoEvents" had to fix this problem ... ?

thx,
Vamp


*** MOD : moved this thread @ winsockvb.com
If I get any help over there I'll update this thread !

piggybank1974
04-30-2003, 04:32 PM
Hi vampire

I'll try to help you on this but i'll need more information.

Conclusion : everything is being send to him, that's not the problem, but it should be send one by one tho ...

it is getting sent one by one is it not?? as you are going thru all possible arrayed sockets.

may be as well, cut down on the size of data you are sending e.g.( the NEW PLAYER string) or use a byte array.

So what is really happing is it going to slow??

one Client is not receiveing the data or what??

Also I take it the code snipet is from the Server side not the client side??

the pig.

vampire
04-30-2003, 04:43 PM
Yep, it's serverside code.
What I actually meant @ that quote you made was that if there are 5 players already connected to the server, then another player joins the game, the position of the first 5 (those who were already connected) should be sent to this new player.

Therefor I use the code :

for i = 1 to ConID
DoEvents
sckplayer(conid).senddata "Newplayer : [" & i & "] ... "
next

With this code the new player (number 6) receives the position of the other 5. Client 6 should receive this data one by one right ? Theoretically it 's like this :

"Newplayer : [" & 1 & "] ... "
"Newplayer : [" & 2 & "] ... "
"Newplayer : [" & 3 & "] ... "
"Newplayer : [" & 4 & "] ... "
"Newplayer : [" & 5 & "] ... "


But what my client receives is :
"Newplayer : [" & 1 & "] ... Newplayer : [" & 2 & "] ...Newplayer : [" & 3 & "] ... Newplayer : [" & 4 & "] ... Newplayer : [" & 5 & "] ... "
---> only 1 line :/

hope it's a bit more clear now ...

Robse
04-30-2003, 05:01 PM
Go over to www.winsockvb.com and read/try the
"Packet Delimiters" tutorial

piggybank1974
04-30-2003, 05:06 PM
hi vamp

are got you now.

here goes what you need is a packet delimeter.

and, and this is important and works well. is change the variable that gets the senddata to a static variable.

some thing like this:


Static strData As String
Dim strTemp As String

winsock1.GetData strTemp
DoEvents
strData = strData + strTemp


then use something like this:

If (Left$(strData, 6) = "I$V^B%") Then
If Right(strData, 6) = "$E(N)D" Then

'the code you want minus the delimeters
strData = vbnullstring
endif
endif


now you may have to rewrite some of your sending code so you can use the split command.

formating text is a good idea as well the reason for this is lets say err!! what you need to do is make all parts of the sending infromation the same side so again you can cut them out:

because your players will not always start at positions 0 to 9 on X,Y


format(len(data),"00000000" )


so by using the above code lets say you would get always 10 characters wide e.g. 00000001, which when you have sent it you can parase this easily as you know it is ten characters wide.

Also there is a more complicated send to try first you need to know the absolute size you want to send, put delimeters on it and put this information(the size) into the send itsself.

I hope this helps a bit.

delimetering is the way to go.

the pig..

vampire
04-30-2003, 05:10 PM
k thanks for the answer guys !
Now I finally know where and how to fix it.

Can't test it @ the moment tho, I'll prolly do it tomorrow.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum