Teen Programmers Unite  
 

 

Return to forum top

Visual Basic Winsock

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 04:16:39 AM

I've made a client and server application...the client is supposed to send a message to the server - a text the client part has...in the server i tried using the Select Case inorder for the server to recognize the two messages but it doesnt work...if you know what i'm talking about please help...else ask me to explain better...

Posted by Psion [send private reply] at August 06, 2002, 07:49:54 AM

Are you complaining that "Select Case" doesn't work with strings?

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 08:11:20 PM

I'm not saying that it doesnt work with them but I cant get the server to display the string in a message...using two different string and select case...any ideas ?

Posted by CodeRed [send private reply] at August 06, 2002, 08:29:10 PM

How about using Winshoe

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 08:37:24 PM

I think this will explain what I mean:

[[Client]]
Private Sub Command1_click()
if winsock.state = sckconnected then
dim A: A = txtMessageA.text
winsock.SendData A
else
msgbox "No Connection"
End If
End Sub

Private Sub Command2_click()
if winsock.state = sckconnected then
dim B: B = txtMessageB.text
winsock.SendData B
else
msgbox "No Connection"
End If
End Sub

[[Server]]
Private Sub Winsock_DataArrival(ByVal bytesTotal as long)
Dim DATA as string
Winsock.GetData DATA
Select Case DATA
Case A
MsgBox DATA
Case B
MsgBox DATA
End Select
End Sub

I know i'm missing something or doing something wrong, any ideas ?

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 10:28:33 PM

Maybe its just me but I dont think 'How about using Winshoe' is very funny

Posted by CodeRed [send private reply] at August 06, 2002, 10:44:16 PM

It's a play on words, by nature they aren't laugh-out-loud funny, just clever. Glad to clear that up for you.

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 10:48:46 PM

Glad you cleared it up but I asked for help not clever words...

Posted by CodeRed [send private reply] at August 06, 2002, 10:56:57 PM

Well, seeing as how you are not paying for this service, I guess you'll just have to take what you can get.

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 11:04:16 PM

If "Winshoe" is all that you can give then you must be one of the top elite programmers around...(Sarcasm)

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 11:05:35 PM

Another thing, I dont have time to argue with other people in a Forum...hopefully you'll understand.

Posted by CodeRed [send private reply] at August 06, 2002, 11:07:44 PM

Argue? Who's argueing? I simply stated that this is a free, public message board, you don't own your thread nor do you controll the subsequent contents of it.

Posted by CodeRed [send private reply] at August 06, 2002, 11:10:08 PM

"If "Winshoe" is all that you can give then you must be one of the top elite programmers around...(Sarcasm)"

I don't dare mess around with Visual Basic, no, VB is much to elite for me. I stick with the newbie stuff, you know, OpenGL and Win32 under C++.

Posted by Spyder_Y3K [send private reply] at August 06, 2002, 11:15:30 PM

Good for you - should be very proud of yourself

Posted by CodeRed [send private reply] at August 06, 2002, 11:20:40 PM

Awww, I made a new friend... LOL

Posted by buzgub [send private reply] at August 07, 2002, 12:28:30 AM

back to the question:

When you send A with the client's winsock control, you send the contents of A, not A itself. Therefore, when on the server you try to check if the data you've received is equal to A it isn't true (unless the content of A in the client was an empty string).

Posted by Spyder_Y3K [send private reply] at August 07, 2002, 01:06:33 AM

How can I have A equal some text but have the server recognize it as just "A"

Posted by buzgub [send private reply] at August 07, 2002, 01:11:32 AM

You should probably think in terms of messages rather than variables for this sockets stuff.

you could reserve the first character of a message for "mode" or "command" information, and use the mid() function to get it out again.

Posted by Spyder_Y3K [send private reply] at August 07, 2002, 01:48:20 AM

I still dont get it :(

Posted by buzgub [send private reply] at August 07, 2002, 02:04:01 AM

When you send the message across the wire, only the message itself is sent. The expression that produced this message (the variable, in this case) is not part of that information. You need to send that extra information along as well somehow. I can't think of how to put it into simpler terms, so that will have to do.

Posted by Spyder_Y3K [send private reply] at August 07, 2002, 02:06:43 AM

I get you, but I dont understand how to do that

Posted by buzgub [send private reply] at August 07, 2002, 02:21:06 AM

There is a function in VB called "mid". You can use it to extract a portion of a string.

You could change 'winsock.SendData A' to 'winsock.SendData "A" + A' (you'll want to change some variable names here, btw). Now, the data being sent, if variable A contains the string "Don't Panic!", is "ADon't Panic!". If variable A has the word "hello", the data sent over the network will be "Ahello".

Now, on the other end, we use that mid function. I can't remember if it treats strings like they start at 0 or not, so you'll have to look it up. I'll act as if it does. Your documentation will probably say something like this:

mid (something as string, start as integer, [length as integer]) 


now on your server, we change "Dim DATA as string" to something like:
 dim RawData as string, mode as string, data as string


Add the following two lines of code, just after you get all the data (now putting it into RawData):

mode = mid(RawData, 0, 1)
data = mid(RawData, 1)


now, you "Select Case mode" and "msgbox data". Your cases will need to be strings, too.

This is all untested, but I'm sure the theory of it is sound, if not the code.
Posted by Spyder_Y3K [send private reply] at August 07, 2002, 02:44:30 AM

I'll try that thanx for your help...

Posted by eXorcus [send private reply] at August 07, 2002, 09:02:12 AM

Just a note, in VB the MID$ function treats strings as if they start at 1, so to get the first char in the string you would need mode$ = MID$(RawData, 1, 1)

Also, if you just want to access the first character, it's easier (Possibly faster?) to use the Left$ function:
mode$ = Left$(RawData, 1) '<--using above example string, Would return just A

To access the rest of the string, (Everything to the right of 1st character), you can use the Right$ and Len functions
data$ = Right$(RawData, Len(RawData) - 1)

It's trivial though, the Mid$ function will work perfectly fine. =P

Posted by AngelOD [send private reply] at August 07, 2002, 03:40:38 PM

CodeRed >>> This thread actually made me laugh, cuz there's actually an internet component package for Delphi/Kylix called "Indy", that used to bear the name "Winshoes". :D

Posted by taubz [send private reply] at August 07, 2002, 06:52:14 PM

Oh I get it now....

Posted by CodeRed [send private reply] at August 08, 2002, 12:52:57 AM

It's ABOUT time....

Posted by Spyder_Y3K [send private reply] at August 09, 2002, 02:07:54 AM

I think this code would work but I have another problem, how would I make it do the same thing mentioned above but with other "Case's" that need the 'DATA' in original format:

[[Server]]
Private Sub Winsock_DataArrival(byVal bytesTotal as long)
Dim DATA as string
Winsock.GetData DATA
Select Case DATA
Case "SpecificMSG1"
MsgBox "Specific Message 1"
Case "SpecificMSG2"
MsgBox "Specific Message 2"
End Select
End Sub

If you can please show me where i'd have to add the
Mode$ = Left$(RawData,1) and Data$ = Right$(RawData,len(RawData)-1)
and any other code that would go with them
One more thing, I know i'm probably wrong but isnt 'DATA' supposed to be in place of 'RawData' ?

Posted by buzgub [send private reply] at August 09, 2002, 02:19:51 AM

you should be doing your select case on the mode variable, now. You should also be GetDataing into rawdata (and doing the parsing directly afterwards), and msgboxing data.

You should probably consider rewriting this subroutine.

Posted by Spyder_Y3K [send private reply] at August 09, 2002, 04:23:04 AM

Hey thanx used the example and figured it out...

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.