Sign in to follow this  
Followers 0
DarkNecromancer

Network Functions

5 posts in this topic

#1 ·  Posted (edited)

Hi, I'm trying to use the TCP connect to get my applications networkable. But I'm having problems getting it to work, and I've never had problems before and i can't figure out why I am now. So I come to you with this question, what am I doing wrong? I whipped up this code to see whats happening and as far as I can tell its accepting the connection from the second application correctly but it don't register when the user has left the socket.

SERVER CODE:

TCPStartup()
$MainSocket = TCPListen( "127.0.0.1", 7000 )
Dim $socket=-1
WHile 1
    If $socket >= 0 Then
        SplashTextOn( "Connected", "Main Socket State: " & $MainSocket & @CRLF & "Socket state: " & $socket )
    Else
        $socket = TCPAccept($MainSocket)
    EndIf   
    SplashTextOn( "Result", "Main Socket State: " & $MainSocket & @CRLF &  "Socket state: " & $socket )
    Sleep(1000)
WEnd
TCPShutdown()

Client:

TCPStartup()
Dim $Socket = -1
While 1
    If $socket = -1 Then
        $socket = TCPConnect( "127.0.0.1", 7000 )
    Else
        msgbox(0,"","Connected")
        Exit
    EndIf
WEnd
TCPShutdown()
Edited by DarkNecromancer

Share this post


Link to post
Share on other sites



I was doing some more searcing around and I was looking around in the help file at the example code for the send and recv functions. Now the server client setup works only because the server and client communicate that they are closing. I would think that if the client crashed thent he server would be stuck and would not be accecable. So does this mean that there isn't any way ot monitor the socket itself to see that status of the socket whether are connections pending, someone connected, or no one? I suppose you could code a command time lapse socket release but I was wondering if anyone knows a better way?

~Dark

Share this post


Link to post
Share on other sites

OO thanks, I will check it out

Share this post


Link to post
Share on other sites

Hmm maybe I'm missing something but I change the server code to

Else
        $socket = TCPAccept($MainSocket)
        TCPRecv( $socket, 1024 )
        $err = @Error 
    EndIf   
    SplashTextOn( "Result", "Main Socket State: " & $MainSocket & @CRLF &  "Socket state: " & $socket & @CRLF   & "@Error Value" & $err)
    Sleep(1000)
and @Error is -1 while not connected, changes to 0 when the client connects, but stays 0 even after the client disconnects. I have the latest autoit beta so i guess i can just transmit a termination code and just hope no 'weird stuff' happens

Share this post


Link to post
Share on other sites

Does anyone have any working server client code?? cause I need this for a school project or i'm going to have to write it in C.

~Dark

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