View Full Version : TCP UPD Example server and client Message
Laatwaai
21-08-2010, 12:00
Halo, :)
How is everyone?
Ja, well okay um i have been looking at the TCP/UPD example in Thinbasic samples.
In the code there is a function that is used to send a data packet declared as sMessage
Client Side
gData.InfoData.iBroadcast.sMessage = "Something"
This is what the client sends to the server.
I am struggling, with getting the IF statement working, what i want to do is that on the server side if a message for example "Somthing" gets received it should respond by creating a MsgBox 0, "success!"
Server Side
If gData.InfoData.iBroadcast.sMessaget(CBHNDL) = "Something" Then
MsgBox(0, "success?")
I have to get it so that if the message is received that it displays the msgbox.
Thanks for the help in advance ;)
ErosOlmi
21-08-2010, 12:11
Hi Laatwaai and welcome to thinBasic community forum.
What exactly is not working?
Do you get a runtime error message?
Or are you haveing un-expected results?
There are two kind of IF ... statements: single line or multiple line
Single line it means all the IF statement must be on a single line
Multiple lines means the IF statement must finish with a END IF
Your example seems breaking single line rule.
Anyway, any more info would be precious to try to understand the problem.
Ciao
Eros
Laatwaai
21-08-2010, 12:26
Hey, Thank you very much :P
The script it self is working, i just want to add a statement which i showed above before, but im not 100% sure if its correct syntax.
Ah i was using one line IF statement. I fixed it up, i think but what i want to do is that, when the server receives the "smessage"
from the client
line 166 in the client sample -
gData.InfoData.iBroadcast.sMessaget = "Hey"
i want to make it that if the server receives the "sMessaget" from the client that states a keyword such as "Hey"
line 144 in the Server sample -
WriteLog CBHNDL, " Message is: " & gData.InfoData.iBroadcast.sMessage
I want to make an if statement for the gData.InfoData.iBroadcast.sMessage if it contains the keyword "Hey' that it creates the msgbox
Thanks, i hope that makes sense, in some way.
ErosOlmi
21-08-2010, 13:26
Check also example in http://community.thinbasic.com/index.php?topic=494.0
Regarding IF I think you can use something like
DIM lPos AS LONG
lPos = INSTR(ucase$(gData.InfoData.iBroadcast.sMessage), "HEY") '---All UCASE because INSTR is case sensitive
IF lPos THEN
MSGBOX 0, "HEY is present at position " & lPos
END IF
Laatwaai
21-08-2010, 13:33
Haha, excellent i see how you used the function, i will learn well from this example.
Thanks for your time Eros
I will contiune working on it and learning, if i make any good improvements will post them ;)
Cheers
ErosOlmi
21-08-2010, 13:43
Attention to firewalls also for local communications
Under Windows 7 you have to authorize your scripts to access network and/or open some ports both as client or as server.
Under Windows XP if firewall is on you have to authorize your application (thinBasic.exe) to access some ports.
For testing it is better to temporarily switch off any firewall
Michael Hartlef
21-08-2010, 13:50
Hi Laatwai and welcome on the board.
I attached Eros Chat example to my post, so you can see in a different example how messages are sent and received.
Cheers
Michael
Laatwaai
21-08-2010, 13:57
Hey Eros thanks yeah im doing it on my local host 127.0.0.1 I wanted to do a test over my network using the 192 IP, range which worked fine :) thanks for all the help.
Thanks Michael looks interesting ill look at it tonight ;)
Thanks for all the help and warm welcomes ^^
Take care
Cheers