Jump to content

HELP ON TCP FUNCTION


Recommended Posts

TCPStartUp()
Global $Server = "smtp.9online.fr"
Global $ServerIp = TCPNameToIP($Server)
; Start The TCP Services
;==============================================
; Connect to a Listening "SOCKET"
;==============================================
$socket = TCPConnect($ServerIp, 25 )
Msgbox(0,"",$socket)
If $socket <> -1 Then
    Sleep(100)
    $MainSocket = TCPRecv($socket, 1024)
    Msgbox(0,"",$mainsocket )
; Initialize a variable to represent a connection
;==============================================
    Sleep(100)
    $sData = "EHLO" & @ComputerName & @CRLF
    If StringLeft($sData, 3) = "220" Then
        TCPSend($Socket,"EHLO")
        If TCPSend($Socket, $sData) > 0 Then
            Sleep(100)
        Endif
    Endif
Endif
TCPCloseSocket ( $socket )
TCPshutdown()

I have trouble with TCPRECV wihch receive nothing. Someone can help me ?

Best regards

Link to comment
Share on other sites

You need to put the recv in a While statement

While 1
TCPRecv($Socket, 512)
WEnd

It will not always send immediatly. This is fairly simple. Please check my signature for TCP examples that may help you.

Specific example is TCP Client Example below the links in the first post.

Edited by AutoIt Smith
Link to comment
Share on other sites

You need to put the recv in a While statement

While 1
TCPRecv($Socket, 512)
WEnd

It will not always send immediatly. This is fairly simple. Please check my signature for TCP examples that may help you.

Specific example is TCP Client Example below the links in the first post.

I try with While 1 --Wend but the problem is always the same

TCPStartUp()
Global $Server = "smtp.9online.fr"
Global $ServerIp = TCPNameToIP($Server)
; Start The TCP Services
;==============================================
; Connect to a Listening "SOCKET"
;==============================================
$socket = TCPConnect($ServerIp, 25 )
Msgbox(0,"",$socket)
If $socket <> -1 Then
    Sleep(100)
    
    While 1
    $Data = TCPRecv($Socket, 1048)
    If $Data = "~bye" Then
        MsgBox(16, "Session Ended", "Connection Terminated.")
        Exit
    ElseIf $Data <> "" Then
; Unconditional Receive
        MsgBox(0, "Received Packet", $Data)
    EndIf
WEnd
    

; Initialize a variable to represent a connection
;==============================================
    Sleep(100)
    $sData = "EHLO" & @ComputerName & @CRLF
    If StringLeft($sData, 3) = "220" Then
        TCPSend($Socket,"EHLO")
        If TCPSend($Socket, $sData) > 0 Then
            Sleep(100)
        Endif
    Endif
Endif
TCPCloseSocket ( $socket )
TCPshutdown()
Link to comment
Share on other sites

Please take a serious look at my examples and even use the TCP Client Example. You seem to stray from the fact that you may need a GUI for sending information. You must be able to send the command while listening. Review the help file and the TCP Client/ TCP Server Communicator for help.

Link to comment
Share on other sites

I have trouble with TCPRECV wihch receive nothing. Someone can help me ?

well, I did a telnet to that server on port 25. It simply does not answer, so it's no wonder TCPRecv() does not receive anything!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

The TCPAccept function is missing.

TCPStartup()
Global $Server = "smtp.9online.fr"
Global $ServerIp = TCPNameToIP($Server)
; Start The TCP Services
;==============================================
; Connect to a Listening "SOCKET"
;==============================================
$mainsocket = TCPConnect($ServerIp, 25)
MsgBox(0, "", $socket)
While 1
    $socket = TCPAccept($mainsocket)
    If $socket <> - 1 Then
        Sleep(100)
        Do
            $recvdata = TCPRecv($socket, 1024)
        Until $recvdata <> ""
        MsgBox(0, "", $recvdata)
        ; Initialize a variable to represent a connection
        ;==============================================
        Sleep(100)
        $sData = "EHLO" & @ComputerName & @CRLF
        If StringLeft($sData, 3) = "220" Then
            TCPSend($socket, "EHLO")
        EndIf
        If TCPSend($socket, $sData) > 0 Then
            Sleep(100)
        EndIf
    EndIf
WEnd
TCPCloseSocket($mainsocket)
TCPShutdown()

#)

edit: Did a Tidy on the script.

Edited by nfwu
Link to comment
Share on other sites

The TCPAccept function is missing.

TCPAccept() is only for servers. He is trying to write a client! If TCPAccept() was missing, then TCPListen() is missing as well!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Ah... my apologies.

I thought he was writing a server.

No problem.

@LOULOU: Try sending something to the server first.

I'm pretty sure the problem is somewhere else. As I said earlier:

I did a telnet to that server on port 25. It simply does not answer, so it's no wonder TCPRecv() does not receive anything!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...