Sign in to follow this  
Followers 0
D4rk^S0ul

TCP Help

3 posts in this topic

#1 ·  Posted (edited)

I was wonding what was wrong with my code i am trying to send a txt file through tcp i was wonding what was wrong with

$g_IP = "127.0.0.1"

TCPStartUp()

$MainSocket = TCPListen($g_IP, 65432,  100 )
If $MainSocket = -1 Then Exit

While 1
$ConnectedSocket = TCPAccept( $MainSocket)
If $ConnectedSocket >= 0 Then
    msgbox(0,"","Client Connected")
    ExitLoop
EndIf
Wend

While 1
    $Recv = TCPRecv($ConnectedSocket, 100)
    If $Recv = "SendLog" Then
        MsgBox(0, "Sending", "Client requested file!")
        $File = FileRead("C:\Random.txt", 100)
        Sleep(500)
        TCPSend($ConnectedSocket, $File)
    EndIf
    Sleep(100)
WEnd

$g_IP = "127.0.0.1"

TCPStartUp()

$Socket = TCPConnect( $g_IP, 65432)
If $Socket = -1 Then Exit

TCPSend($Socket, "SendLog")
FileWrite("C:\Random2.txt", $Recv)

It connects ok and if i but filewrite in a loop then it writes the txt again and again into the file but not like this i was wonding why?

Edited by D4rk^S0ul

Share this post


Link to post
Share on other sites



It is possible that the client is sending the file before the server is ready to receive. In other words, because you have msgboxes, your script pauses (on the one side only), while on the other side the script is still running and sending the file. Try replacing the msgboxes with traytips.

Oh, now that I looked more carefully at it, there's another issue. How does the writing script know what to write? There is no recv on that side. The variable hasn't been declared either... if the scripts were run separately (which they are supposed to because it is tcp), the writing script will error out. You still need a recv loop.

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  
Followers 0