Sign in to follow this  
Followers 0
Blastradius

TCP Problematics..

6 posts in this topic

I have used the TCP method of connecting for while now, which works fine for a single user, however thats where my problem comes in. I have no idea how to set a script up so it can support multiple users.. is it even possible? It should be somehow, i've looked at UDP too but that really didnt help me out either. Say for example i want a hundered users to connect to the 'server' and do something with it, how would i go about doing that? Thanks for the help..

Client/Server Code

==============================================

Client ('messages' are set by hotkey which works fine):

; Server Connection
;==============================================
$serverIP = InputBox( "Server IP", "Please insert the IP of the server to connect with." )
$serverPort = InputBox( "Server Port", "Please insert the port of the server to connect with." )

; Global Used Variable
;==============================================
$isActive = 1
$isMessage = -1

; Safe checking the required port
;==============================================
If StringLen( $serverPort ) == 0 OR StringIsAlNum( $serverPort ) == 0 Then
    $serverPort = "22000"
EndIf

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

; Create a Connected Socket
;==============================================
$clientStream = TCPConnect( $serverIP, $serverPort )
If @error OR $clientStream = -1 Then
    MsgBox( 4096, "DoH!", "Server connection failed!" )
    Exit
EndIf

; Look for / send keys to the server
;==============================================
While $isActive
    If $isMessage <> -1 Then
        TCPSend ( $clientStream, $isMessage )
        $isMessage = -1
    EndIf
    
    Sleep( 50 )
Wend

; Close the TCP Services (if need do)
;==============================================
TCPShutDown()

Share this post


Link to post
Share on other sites



Im surpised i didnt find that one :whistle:

Anyway thanks for it, but this script leaves me with one question..

Where does $Data = "~bye" come from? Is it automaticly send when a socket closes?

Share this post


Link to post
Share on other sites

Where does $Data = "~bye" come from? Is it automaticly send when a socket closes?

It comes from the client, probably sent when the client shuts down or disconnects.

A little reading goes a long way. Post count means nothing.

Share this post


Link to post
Share on other sites

Im surpised i didnt find that one :whistle:

Anyway thanks for it, but this script leaves me with one question..

Where does $Data = "~bye" come from? Is it automaticly send when a socket closes?

I remember someone asked that question a long long time ago. ~bye is sent by the client to indicate that it wants to close the connection, then the server automatically closes the connection. You can remove this whole bit with ~bye, because in AutoIt both client and server can close a connection. Just remember to trap @error from a TCPRecv() function, to know if someone disconnected or not.

Share this post


Link to post
Share on other sites

Allright, i used to did it that way so i wondered what the difference was anyway.

Thanks xD

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