Sign in to follow this  
Followers 0
d0n

TCPlisten

5 posts in this topic

This code doesn't work when i put TCPListen, but it works when i use TCPConnect.

I am trying to listen to this ip/port for incoming messages, not sure what i am missing.

$ip = "75.150.216.162"
$port = 4099

TCPStartup()

$socket = TCPListen($ip, $port)

While 1
    $recv = TCPRecv ($socket, 5000 )
    If $recv <> "" Then MsgBox ( 4096, "recv", $recv )
WEnd

Share this post


Link to post
Share on other sites



So it's the server code. Have a look in the help file for the example of TCPAccept() function.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I tried adding a TCPAccept function but TCPListen still wont return anything, however TCPConnect will

$ip = "75.150.216.162"
$port = "4099"

TCPStartup()

$socket = TCPListen($ip, $port)

While 1
    $Accepted = TCPAccept($socket)
    $recv = TCPRecv ($Accepted, 5000 )
    If $recv <> "" Then MsgBox ( 4096, "recv", $recv )
WEnd
Edited by d0n

Share this post


Link to post
Share on other sites

What is this IP address? it's yours? or you're trying to listen to another IP address ports, not yours? Again, read the functions description in the help file. Check the return value of a function and write correct code.

Share this post


Link to post
Share on other sites

learning TCP is the hard part... after that most times its a breeze

$ip = @IpAddress1 ;"75.150.216.162" try that instead
$port = "4099"

TCPStartup()

$socket = TCPListen($ip, $port, 100);the 100 is the connections (your using the default... maybe thats it

While 1
    $Accepted = TCPAccept($socket)
if $Accepted <> -1 then
    $recv = TCPRecv ($Accepted, 5000 )
    If $recv <> "" Then MsgBox ( 4096, "recv", $recv )
endif
sleep (100)
WEnd
func onautoitexit ()
TCPclosesocket ($Accepted)
TCPshutdown ()
endfunc

i dunno try that out

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