Results 1 to 6 of 6

Thread: winsock

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Oshawa, Ontario, Canada
    Posts
    88

    Angry

    the error 10048 keeps popping up...Adress In Use

    ok....this is not working. i tried using sock.close on that error but it just doesn't work properly!!

    what i'm doing is having my client connect to my server....when i click the disconnect but it does a winsock.close

    then when i click the connect button again it gives me the error....i'll show you the code for my client and server

    client

    Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
    If Button.Index = 1 Then
    frmOptions.Show 1
    End If

    If Button.Index = 3 Then

    sock.Close

    sock.Connect "127.0.0.1", 7771
    Button.Enabled = False
    Toolbar1.Buttons.Item(4).Enabled = True

    End If

    If Button.Index = 4 Then
    sock.Close
    Button.Enabled = False
    Toolbar1.Buttons.Item(3).Enabled = True

    End If

    If Button.Index = 58 Then
    Dim Answer
    Answer = MsgBox("Are you sure you want to quit? ", vbExclamation + vbYesNo, "Exit?")
    If Answer = vbYes Then
    End
    End If
    End If

    End Sub


    Server

    Option Explicit
    Dim Buffer As String

    Private Sub Form_Load()
    Sock.Listen
    End Sub


    Private Sub Sock_Close()
    If Sock.State <> sckClosed Then
    Sock.Close
    End If
    End Sub

    Private Sub Sock_ConnectionRequest(ByVal requestID As Long)

    sock2(sock2.UBound).Accept requestID

    Load sock2(sock2.UBound + 1)
    sock2(sock2.UBound).LocalPort = sock2(sock2.UBound - 1).LocalPort + 1

    End Sub

    Private Sub sock2_Close(Index As Integer)
    sock2(Index).Close
    End Sub

    Private Sub sock2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    sock2(Index).GetData Buffer, vbString
    Text1.Text = Text1.Text + Trim(Buffer) + vbNewLine

    If Left(Buffer, 6) = "/Name:" Then
    lstNames.AddItem Right(Buffer, Len(Buffer) - 6)
    End If

    End Sub

    all of this code works....i can connect multiple clients to the server but if i click disconnect on one client and try to click connect again after i've already been connected once using the same client it gives me the error!!

    please help
    -|Kn|gHt|
    MSN - [email protected]

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Oshawa, Ontario, Canada
    Posts
    88
    someone please reply!!
    -|Kn|gHt|
    MSN - [email protected]

  3. #3
    Member
    Join Date
    Nov 2000
    Location
    Manila, Philippines
    Posts
    51

    Same as me...hehehe

    Knight, what you are having is a nightmare!
    Just like what I had... hehehe

    Anyway, I solved mine.
    Here is how I solved it...

    I made some kind of my own protocol... I'll discuss the disconnection part.

    REMINDER: (this works for me, Dont assign a localport for the client just invoke Connect: Winsock.Connect RemoteHost,RemotPort)

    1.> The client sends a message: "/CloseRequest"
    2.> The server receives and sends back a confirmation: "/CloseGoAhead"
    3.> The server then closes its winsock connection with the client: Winsock.Close
    4.> [On the client side] Client receives the message: "/CloseGoAhead"
    5.> Client then closes its connection too: Client.Close
    6.> Im happy! (I can reconnect back any instant!!!)

    Explanation: (this is what I think happened to yer situation... Hey! I could be wrong, but It solved my problem.)
    When the client is connected to the server... and client wants to disconnect, client invokes a .Close method. Thereby closing(freeing) its port... However, the server winsock, is still communicating(using) that port. It had no idea that the client is AWAY/GONE... so it must use some kind of a timeout(remember a PING timeout?) which u have to make for it.... but for the meantime, when the timeout does not go off yet, you cant connect to the same port back since the server is still using your localport for some connection/communication...

    Point is: You have to invoke a close method both on the server, and client sides.

    Hope this helps.

    Jonn
    Programmers dont byte, they just nibble a bit.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Oshawa, Ontario, Canada
    Posts
    88
    YOU ARE MY GOD!!

    That fixed everything man....thankyou so much for your help!!
    -|Kn|gHt|
    MSN - [email protected]

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    The reason u got address in use is that some app is already using the port that u want to use, i think.

  6. #6
    Member
    Join Date
    Nov 2000
    Location
    Manila, Philippines
    Posts
    51
    Good. Thanks.
    Programmers dont byte, they just nibble a bit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width