Jump to content
Sign in to follow this  
Drew

Help

Recommended Posts

Drew

How do you make it so that you can connect more than 1 client?

SERVER SIDE-

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
$Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

CLIENT CODE-

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
$Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

QUESTION:

How do you insert code where it still gives the autoit colors etc.?

Share this post


Link to post
Share on other sites
Drew

I am still only able to connect 1 client to the server at a time. If one client is connected , and another trys... its ignored.

Share this post


Link to post
Share on other sites
rambo3889

Arrays, look into it in the helpfile


My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! youÂ’re the best in town Fight!

Share this post


Link to post
Share on other sites
Drew

I'm new to all the Network programming commands... I understand arrays but I don't know how I would use them here.

Could you please give me an example?

Edited by Drew

Share this post


Link to post
Share on other sites
James

You need to write out [ autoit ] CODE [ / autoit ] (Without the spaces) - However the tags are broken so I don't recommend them.

Here is a simple array:

$myArray[3] = ["Drew", "JamesB", "Rambo3889"]

If you want advanced array functions then the Array.au3 is what you need :)

Share this post


Link to post
Share on other sites
Drew

Alright , but how would I use this to accept connections and etc. though?

Oh and I'm not going to know whos connecting to the server side program. What would I enter into the array? Also, I'm unsure HOW MANY would need to connect to this. Ugh. I'm beginning to wonder if what I'm doings even possible.

Share this post


Link to post
Share on other sites
LarryDalooza

TCPAccept in your main loop.... if it succeeds... add that socket to an array... cycle through array for TCPRecv ... if TCPRecv fails... remove that socket from the array.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
Drew

Could someone please give me an example? In my mind, I understand how that works... but I'm having trouble directing it to the program.

GREATLY appreciated as I've been trying and trying for some time now. Thanks,

Share this post


Link to post
Share on other sites
Drew

Really need help on this.

Share this post


Link to post
Share on other sites
Drew

I'm going to bed , 1:30am , but I'm going to check this in the morning. Here's my situation.

I need to be able to allow more than 1 connection at a time. I was told to do this:

TCPAccept in your main loop.... if it succeeds... add that socket to an array... cycle through array for TCPRecv ... if TCPRecv fails... remove that socket from the array.

But I don't know how. If someone could PLEASE show me an example of what this person is telling me to do, I would be forever grateful.

Here are my updated scripts:

SERVER-SIDE

HotKeySet('!c', '_Test'); Set up an A hotkey to send the message

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
;~ $Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the client?")
    TCPSend($iConnectedSocket, $Input); Send the data
EndFunc

CLIENT-SIDE

#include <INet.au3>

HotKeySet('!b', '_Test'); Set up an A hotkey to send the message
HotkeySet( '!a', '_Ip')
HotKeySet('{ESC}', '_Close'); Call a close function to close the script when someone presses escape
TCPStartup(); Initialize the TCP functions/library



$Socket = TCPConnect( "64.22.75.225", 7000); Connect to the server
If @error Then; If no connection is made, the server probably is not running, or another error occurs, give an error message to the user
    MsgBox(0x20,"Connection error", "Unable to connect.")
    Exit; Close the script
EndIf
$Ip = _GetIp()
TCPSend($Socket,"Hai there, "&$Ip& " ,has connected client-side to the Anti-Hack."); Just send a test message to make sure we can send some data. ( Not necessary )

While 1
        $sData = TCPRecv($Socket,1024) 
            If $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
WEnd

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the server?")
    TCPSend($Socket, $Input); Send the data
EndFunc

Func _Ip()
    TcPSend($Socket, "The users IP is: "&$Ip)
EndFunc

Func _Close()
    TCPCloseSocket($Socket); Close the socket to the server
    TCPShutdown(); Deinitialize the TCP functions/library
    Exit; Close the script
EndFunc

Share this post


Link to post
Share on other sites
SmOke_N

Don't recreate new threads when it is the same topic just because you aren't getting answers fast enough. That's a quick way to get posting privileges taken away all together.

If you don't get an answer within 24 hours, then you can bump your thread... if you bump it 3 times, consider it dead...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×