Jump to content

where is my problem?


Recommended Posts

HotKeySet("^+x", "Exit_client")

Global $myip=@IPAddress1
Global $connect=False
Global $connection
Global $packets

MsgBox(1,"",$myip)

TCPStartup()

$mainsocket=TCPListen($myip, 23465, 100)
if $mainsocket = -1 then Exit

While $connect=False
    $connection=TCPAccept($mainsocket)
    $connect=True
    If $connect=True Then
        ToolTip("connection established")
        Sleep(3000)
        ToolTip("")
    EndIf
    while $connect=True
        $packets=TCPRecv($mainsocket, 1024)
        if $packets <> "" Then
            if $packets = "test" Then
                MsgBox(1, "test", "if you can see this, we have connection! =D")
                $choice=MsgBox(3, "test", "end connection?")
                if $choice=6 Then
                    MsgBox(1,"test","WHY?!?!?! we're ending this now anyway!")
                    Exit
                Else
                    MsgBox(1,"test", "so that's it!? you're going to be an ass like that?!")
                    Exit
                EndIf
            EndIf
        EndIf
    WEnd
WEnd

Func Exit_client()
    Exit
EndFunc

my little client. made after studying a different code on the same subject. i've looked at them both and they do the same thing.

my problem, however, is with the sender!

...

i think so anyway...

Global $myip=@IPAddress1
Global $connectto
Global $contry

TCPStartup()

$mainsocket2=TCPListen($myip, 23465, 100)
if $mainsocket2= -1 Then Exit

$connectto=InputBox("tcp client thing", "put in ip to connect to","127.0.0.1")

$contry=TCPConnect($connectto,23465)

if $contry=-1 Then 
    MsgBox(1,"problem","not working")
Else
    TCPSend($mainsocket2, "test")
EndIf

after a while it shows the not working message, meaning i messed something up. BUT WHAT?

Link to comment
Share on other sites

First of all, your Internet router must forward the TCP port (in your case 23465) to your machine

Second,

Your main loop really never loops.... lol

Look:

While $connect=False
     $connection=TCPAccept($mainsocket)
     $connect=True
Here you $connect is allways true

Change it to:

While $connect=False
    $connection=TCPAccept($mainsocket)
    If (Not @error) And ($connection <> -1) Then
        $connect=True
    EndIf

A better way to write this script would be:

HotKeySet("^+x", "Exit_client")

Global $myip=@IPAddress1
Global $connection
Global $packets

MsgBox(0,"",$myip)

TCPStartup()

$mainsocket=TCPListen($myip, 23465, 100)
if $mainsocket = -1 then Exit
$connection = -1
While $connection == -1
    Sleep( 100 )
    $connection=TCPAccept($mainsocket)
    If (Not @error) And ($connection <> -1) Then
        $connect=True
    EndIf
WEnd

ToolTip("Connection Established")
Sleep(3000)
ToolTip("")

while True
    $packets=TCPRecv($mainsocket, 1024)
    if $packets <> "" Then
        if $packets = "test" Then
            MsgBox(1, "test", "if you can see this, we have connection! =D")
            $choice=MsgBox(3, "test", "end connection?")
            if $choice=6 Then
                MsgBox(1,"test","WHY?!?!?! we're ending this now anyway!")
                Exit
            Else
                MsgBox(1,"test", "so that's it!? you're going to be an ass like that?!")
                Exit
            EndIf
        EndIf
    EndIf
WEnd

Func Exit_client()
    Exit
EndFunc

Good luck!

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

First of all, your Internet router must forward the TCP port (in your case 23465) to your machine

Second,

Your main loop really never loops.... lol

Look:

While $connect=False
     $connection=TCPAccept($mainsocket)
     $connect=True
Here you $connect is allways true

Change it to:

While $connect=False
    $connection=TCPAccept($mainsocket)
    If (Not @error) And ($connection <> -1) Then
        $connect=True
    EndIf

A better way to write this script would be:

HotKeySet("^+x", "Exit_client")

Global $myip=@IPAddress1
Global $connection
Global $packets

MsgBox(0,"",$myip)

TCPStartup()

$mainsocket=TCPListen($myip, 23465, 100)
if $mainsocket = -1 then Exit
$connection = -1
While $connection == -1
    Sleep( 100 )
    $connection=TCPAccept($mainsocket)
    If (Not @error) And ($connection <> -1) Then
        $connect=True
    EndIf
WEnd

ToolTip("Connection Established")
Sleep(3000)
ToolTip("")

while True
    $packets=TCPRecv($mainsocket, 1024)
    if $packets <> "" Then
        if $packets = "test" Then
            MsgBox(1, "test", "if you can see this, we have connection! =D")
            $choice=MsgBox(3, "test", "end connection?")
            if $choice=6 Then
                MsgBox(1,"test","WHY?!?!?! we're ending this now anyway!")
                Exit
            Else
                MsgBox(1,"test", "so that's it!? you're going to be an ass like that?!")
                Exit
            EndIf
        EndIf
    EndIf
WEnd

Func Exit_client()
    Exit
EndFunc

Good luck!

while i'm thankful for your making-my-code-look-better-ness (i forgot the word. lol.), alas, you didn't quite answer my question.

first of all, i don't have a router. this is none of your fault.

however, the question was about the sender thing, not the receiver. i'm pretty sure i nailed it with the receiver.

why does my sender thingy doesn't send?

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...