Sign in to follow this  
Followers 0
GodForsakenSoul

TCPListen

5 posts in this topic

#1 ·  Posted (edited)

i'm trying to set up TCP client for a friend of mine. first i'm going to scare the shit out of him, later we might actually work this into something useful o_o

basically, i'm just messing with the TCP options of autoit right now.

i need to check whether i'm connected.

here's the code so far...

#include "Data\Inet.au3"
HotKeySet("^+{F9}", "killthething")

Dim $YOURIP = _GetIP
Dim $INCOMING
Dim $ALLHELL=0
MsgBox(1, "Your ip is",$YOURIP&" give it to your lord and master!")
TCPStartup()
$INCOMING = InputBox("Incoming connection", "Insert the ip given to you by your lord and master here")
TCPListen($INCOMING)

$ALLHELL is a short for ALLHELLBREAKSLOOSE, and will be used later... xD

i first need to connect to him. so he'll be listening to my ip, and when it connects, accept the connection.

i'm assuming i'm going to need TCPAccept somewhere in this.

i need to check whether i'm connected to him or not.

i have no idea how it's done. suggestions?

the idea is that if i'm connected, it first pops up a "yay, we established connection!" message box and then calls a rather scary function. XD

something like this:

If <check_if_connection_established>=1 then
$ALLHELL=1 ;i'm well aware i can just skip to the call function, but this is what i'm used to. this is more comfortable for me.
endif
if $ALLHELL=1 then
call ScaryAssFunction()

suggestions?

edit: i'm pretty sure $MainSocket = TCPListen($g_IP, 65432, 100 )

helps somehow. question is, how?

Edited by GodForsakenSoul

Share this post


Link to post
Share on other sites



Search for it and read the help file.

Share this post


Link to post
Share on other sites

Search for it and read the help file.

....

you insult me.

i did, infact search for it, and i'm still trying to use the help file to work something out.

i assumed you'd assume i already tried this by myself before actually posting here...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Straight from the help file:

;SERVER!! Start Me First !!!!!!!!!!!!!!!
$g_IP = "127.0.0.1"

; Start The TCP Services
;==============================================
TCPStartUp()

; Create a Listening "SOCKET"
;==============================================
$MainSocket = TCPListen($g_IP, 65432,  100 )
If $MainSocket = -1 Then Exit

;  look for client connection
;--------------------
While 1
$ConnectedSocket = TCPAccept( $MainSocket)
If $ConnectedSocket >= 0 Then
    msgbox(0,"","my server - Client Connected")
    exit
EndIf
Wend

;CLIENT!!!!!!!! Start SERVER First... dummy!!
$g_IP = "127.0.0.1"

; Start The TCP Services
;==============================================
TCPStartUp()

; Connect to a Listening "SOCKET"
;==============================================
$socket = TCPConnect( $g_IP, 65432 )
If $socket = -1 Then Exit

TCPConnect:

Return Value

Success: Returns main socket identifier.

Failure: Returns -1 and set @error according to Windows API WSAGetLasterror return.

If IPAddr is incorrect @error is set to 1.

If port is incorrect @error is set to 2.

Simple Server

I guess I assumed you would have searched competently.

Edited by qazwsx

Share this post


Link to post
Share on other sites

-facepalm-

i honestly forgot about the SITE search option....

i accept your insult wholeheartedly.

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