Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronize Client-Server Data w/ Winsock App

Status
Not open for further replies.

voydangel

Programmer
Dec 10, 2004
18
US
I have an App that is using Winsock to send data back and forth between the host and client. The Host and client Apps are identical. The computer knows "who is who" by the user(s) clicking on a button marked "Run as Host" or "connect to remote Host". Now is where I start to get confused. I want the server to 'request' a username and password.

How would I accomplish this? I had thought about using an "ID character" in front of any winsock.sendData calls, but quickly realized that I would be writing 10s of thousands of lines of code considering that I will need to be synchronizing all the clients to the server and vise-versa. All of the variables will have the exact same names on the host as on the clients, differentiated by username (so theres no variable name conflicts).

If you havnt already guessed..this app is a form of an online RPG. I need to retrieve all of the client users info (such as attribute scores, name, skill names and ratings etc....) and then display that info on the hosts screen. And also allow the host to modify some of the information later if needed. Rather than a long, long, long.......long series of getdata/senddata routines, is there an easier method to "synchronize" variables with winsock?

If I have not been clear in exactly what I need help with, please feel free to ask me any questions. I will be more than happy to help you help me.
 
Is this multiuser?

One guy acts as "host" (server) and the others as "guests" (clients)?

Do the players' copies of the program exchange tightly formatted messages, or "loosey goosey" text, or what? I mean, is there some sort of protocol like:

[tt] verb:parameters[/tt]

If so, why not a new "verb" the server sends that means "prompt the user for a logon, return it to me" along with another verb coming back that means "here's a logon and the user/pw." If not, just pass text with the same meanings.

It seems easy, you just have a connection state array parallel to your Winsock control array. One value means "not logged on" and another means "logged on." Upon a new connection, send the "please log on" until you get a valid logon, then flip the state to "logged on" - otherwise respond to any other input with the logon prompt. On a logoff or disconnect flip the state to "not logged on."

If this game is just head-to-head (or remote player against the local program) it's even easier.
 
If the "host" needs to pull stats from the remote client, just do the same sort of thing with 3 states:

* Not logged on
* Logged on, need stats
* Logged on, play enabled

Then add more "verbs" or whatever you call 'em: "ok, logged on - give me your data" and "ok, here is my data."

Once again, you stay locked in the transitional state until you (server) get what you need.
 
That is a very nice tip, however what I was asking was....
Following is my current code (a snippet, abbr. for size). The question is...is there an easier/more efficient way to do this?

Private Sub WinsockClient_DataArrival(Index As Integer, ByVal bytestotal As Long)

Dim strData, strData2 As String
Static strTemp(10) As String

Call WinsockClient(Index).GetData(strData, vbString)

strData2 = Left(strData, 1)
strData = Mid(strData, 2)

If Len(strData) > 0 And Len(strData2) > 0 Then
'Data recieved successfully
Debug.Print "'" & strData2 & "' recieved on # " & Index

Select Case strData2

Case "M"
MsgBox strData

Case "P"
MsgBox "Password recieved"
strTemp(1) = strData
Debug.Print strTemp(0)
Debug.Print strTemp(1)
WinsockClient(Index).SendData "M" & "Kinda."
DoEvents
If CheckIfUserExists(strTemp(0), strTemp(1)) Then
MsgBox strTemp(0) & " Exists"
If strTemp(1) = frmUsers.datPrimaryRS.Recordset.Fields("Password") Then
MsgBox strTemp(0) & " has logged in with password: " & strTemp(1)
WinsockClient(Index).SendData "M" & "Congratulations, you have successfully logged in."
Call loadNewClient(strTemp(0), strTemp(1))
End If
End If

Case "U"
MsgBox "Username recieved"
strTemp(0) = strData
Debug.Print strTemp(0)

End Select

End If
DoEvents
End Sub
 
In addition to my wondering if there is an easier way to do the above code snippet. I was wondering if anyone could give me a few pointers and or tips to implement a 'whiteboard' in a program. I am using winsock, and want to have something similar to the white board setups in messenger and netmeeting, any help is appreciated. Thanks in advance.
 
For a new and unrelated question, please start a new thread.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top