Jump to content
Sign in to follow this  
Michael36

TCPRecv

Recommended Posts

Michael36

Hi all on my server script here i can't seem to get it to recv text i been looking at some examples and can't fig out what is not right would someone have a idea on this prob?

thank you

Michael

While 1
$Msg = GuiGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

$recv = TCPRecv($socket, 512 )
  If  $recv <> "" Then recv ($edit)

If $msg = $connect Then Connect($edit)
$Socket = TCPAccept( $MainSocket)
If $Socket >= 0 Then
    msgbox(0,"","my server - Client Connected")
EndIf
    
WEnd
;---------------connect---------------------------------
Func Connect($edit)
$g_IP = "127.0.0.1"
TCPStartUp()
$MainSocket = TCPListen($g_IP, 65,  100 )
If $MainSocket = -1 Then Exit
EndFunc
;------------------RECV------------------------
Func recv ($recv)
 GUICtrlSetData($edit, GUICtrlRead($edit ) & ">" & $recv & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites
Nuffilein805

have you managed to connect?

your button can't work i think because your using

$Msg = GuiGetMsg()
and

If $msg = $connect Then Connect($edit)
2 different variables

next thing: why do you build your connect-function with a parameter if you don't need it?

Func Connect()

this will do

same for the recv-function

you asked why it won't work:

as you call your function with a parameter, you should use the right one if you have to call it this way, which is complete nonsens

try this 1:

While 1
$msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

$recv = TCPRecv($socket, 512 )
  If  $recv <> "" Then recv ()

If $msg = $connect Then Connect()
$Socket = TCPAccept( $MainSocket)
If $Socket >= 0 Then
    msgbox(0,"","my server - Client Connected")
EndIf
    
WEnd
;---------------connect---------------------------------
Func Connect()
$g_IP = "127.0.0.1"
TCPStartUp()
$MainSocket = TCPListen($g_IP, 65,  100 )
If $MainSocket = -1 Then Exit
EndFunc
;------------------RECV------------------------
Func recv ()
GUICtrlSetData($edit, GUICtrlRead($edit ) & ">" & $recv & @CRLF)
EndFunc

this 1 should work

last but not least: if your function just has 1 line of code why don't you put it in your loop?

Share this post


Link to post
Share on other sites
Michael36

have you managed to connect?

your button can't work i think because your using

and

2 different variables

next thing: why do you build your connect-function with a parameter if you don't need it?

Func Connect()

this will do

same for the recv-function

you asked why it won't work:

as you call your function with a parameter, you should use the right one if you have to call it this way, which is complete nonsens

try this 1:

While 1
$msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

$recv = TCPRecv($socket, 512 )
  If  $recv <> "" Then recv ()

If $msg = $connect Then Connect()
$Socket = TCPAccept( $MainSocket)
If $Socket >= 0 Then
    msgbox(0,"","my server - Client Connected")
EndIf
    
WEnd
;---------------connect---------------------------------
Func Connect()
$g_IP = "127.0.0.1"
TCPStartUp()
$MainSocket = TCPListen($g_IP, 65,  100 )
If $MainSocket = -1 Then Exit
EndFunc
;------------------RECV------------------------
Func recv ()
GUICtrlSetData($edit, GUICtrlRead($edit ) & ">" & $recv & @CRLF)
EndFunc

this 1 should work

last but not least: if your function just has 1 line of code why don't you put it in your loop?

i'm sorry i have been using autoit for a short time i thought we keep the loop as tight as Possible

like call things from functions .

well thank you for your help learn something new evrytime i psot a prob

thanks

Michael

Share this post


Link to post
Share on other sites
Nuffilein805

no problem

if you want, you can have a look at my server (30k clients)

http://www.autoitscript.com/forum/index.ph...=ST&f=9&t=17275

for your 1-line function:

you do need at least 1 line to call your function, so why don't you use your codeline instead of a function-call

i'd do that for 1-line functions

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.