Solved

Winsock Run-Time Error 126

Posted on 2002-04-20
6
335 Views
Last Modified: 2013-11-13
I am writing client-server program using Winsock, and encouter this error message only when 1st client try to connect to server, the rest of the client connected, don;t have any problem. i am running this program in windows 98 platform.anyone want to comment, my source code as below

CLIENT

Public localIPAddress As String
Public serverIP As String
Public serverPort As Integer
Public playerName As String
Public localPort As Integer
Public totalUnitAvail As Integer
Public myMoney As Currency
Public myUnit As Integer
Public offerUnit As Integer
Public offerPrice As Currency
Public offerSell As Boolean
Public transactionList

Public dbLocation As String
Public dbMydb As Database

Private Sub cmdAccept_Click()
On Error GoTo errorHandler
    cmdAccept.Enabled = False
    cmdCancel.Enabled = False
   
    If (offerSell) Then
        Dim moneyNeeded As Currency
        moneyNeeded = offerUnit * offerPrice
        If (moneyNeeded > myMoney) Then
            MsgBox "You don't have enough money to buy from server selling"
        Else
            udpPeer.SendData "[CACCSELL][" & localIPAddress & "][" & localPort & " ][" & playerName & " ]"
            updateListBox ("Try to BUY from server...")
        End If
    Else
        If (myUnit >= offerUnit) Then
            udpPeer.SendData "[CACCBUY][" & localIPAddress & "][" & localPort & " ][" & playerName & " ]"
            updateListBox ("Try to SELL to server...")
        Else
            MsgBox "You don't have enough unit to sell to server"
        End If
    End If
Exit Sub
errorHandler:
    serverCloseEvent
End Sub

Private Sub cmdCancel_Click()
    udpPeer.SendData "[CANCEL]"
    cmdAccept.Enabled = False
    cmdCancel.Enabled = False
End Sub

Private Sub cmdTransaction_Click()
    frmTransaction.Show vbModal
End Sub

Private Sub Form_Load()
    dbLocation = App.Path + "\client.mdb"
    Set dbMydb = OpenDatabase(dbLocation)
   
    serverPort = 7172

    localIPAddress = udpPeer.LocalIP
    resetGame
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim ans As String
    If (udpPeer.State > 0) Then
        ans = MsgBox("You are connected to server, are you sure you want to exit?", vbYesNo, "Exit")
        If ans = vbYes Then
            dbMydb.Close
            closeConnection
        Else
            Cancel = 1
        End If
    End If
End Sub


Private Sub mnConnect_Click()
    frmClientConnect.Show vbModal
End Sub

Private Sub mnDisconnect_Click()
    cmdAccept.Enabled = False
    cmdCancel.Enabled = False
   
    closeConnection
    cmdTransaction.Enabled = True
End Sub

Private Sub mnExit_Click()
    For I = Forms.Count - 1 To 0 Step -1
       Unload Forms(I)
    Next I
    End
End Sub

Private Sub udpPeer_DataArrival(ByVal bytesTotal As Long)
On Error GoTo errorHandler
    Dim dataReceived As String
    Dim tempPrice As String
    Dim tempPlayerName As String
    Dim tempIPAddress As String
    Dim tempPortNo As Integer
    Dim upperbound As Integer
    Dim recTransaction As Recordset
   
    udpPeer.GetData dataReceived
   
    If InStr(1, dataReceived, "[CONNECTOK]", vbTextCompare) > 0 Then
        updateListBox ("Connected to Market Server successfully")
    ElseIf InStr(1, dataReceived, "[SELL]", vbTextCompare) > 0 Then
        '[SELL][UNIT][PRICE]
        offerUnit = Int(processData(dataReceived))
        offerPrice = Int(processData(dataReceived)) / 100
       
        updateListBox ("Server wish to SELL " + CStr(offerUnit) + " units of PINK at $" + CStr(offerPrice))
        lblPrice.Caption = CStr(Format(offerPrice, "###0.00"))
        lblOfferUnit.Caption = CStr(offerUnit)
        lblMode.Caption = "SELL"
        lblSellBuy.Caption = "$$ Needed: "
        lblMoneyNeeded.Caption = CStr(Format(offerUnit * offerPrice, "###0.00"))
       
        offerSell = True
        cmdAccept.Enabled = True
        cmdCancel.Enabled = True
    ElseIf InStr(1, dataReceived, "[BUY]", vbTextCompare) > 0 Then
        '[BUY][UNIT][PRICE]
        offerUnit = Int(processData(dataReceived))
        offerPrice = Int(processData(dataReceived)) / 100
       
        updateListBox ("Server wish to BUY " + CStr(offerUnit) + " units of PINK at $" + CStr(offerPrice))
        lblPrice.Caption = CStr(Format(offerPrice, "###0.00"))
        lblOfferUnit.Caption = CStr(offerUnit)
        lblMode.Caption = "BUY"
        lblSellBuy.Caption = "$$ Earned: "
        lblMoneyNeeded.Caption = CStr(Format(offerUnit * offerPrice, "###0.00"))
       
        offerSell = False
        cmdAccept.Enabled = True
        cmdCancel.Enabled = True
   
    ElseIf InStr(1, dataReceived, "[CACCSELLRSLT]", vbTextCompare) > 0 Then
        '[CACCSELLRSLT][IP][PORT][NAME]
        tempIPAddress = Trim(processData(dataReceived))
        tempPortNo = Int(processData(dataReceived))
        tempPlayerName = Trim(processData(dataReceived))
        resetScreen
        If (tempIPAddress = localIPAddress And tempPortNo = localPort And tempPlayerName = playerName) Then
            upperbound = UBound(transactionList, 1)
            ReDim Preserve transactionList(upperbound + 1) As Variant
            transactionList(upperbound) = Array(offerUnit, offerPrice, "BUY")
            myUnit = myUnit + offerUnit
            myMoney = myMoney - (offerPrice * offerUnit)
            updateListBox ("You SUCCESSFULLY buy")
           
            Set recTransaction = dbMydb.OpenRecordset("transaction", dbOpenTable)
            recTransaction.AddNew
            recTransaction("Quantity") = offerUnit
            recTransaction("Price") = offerPrice
            recTransaction("Transaction") = "BUY"
            recTransaction("Cost") = offerPrice * offerUnit
            recTransaction.Update
            recTransaction.Close
        Else
            updateListBox ("You FAILED to buy")
            updateListBox ("Buy success for " + tempPlayerName + " at " + tempIPAddress + "," + CStr(tempPortNo))
        End If
        checkStatus
    ElseIf InStr(1, dataReceived, "[CACCBUYRSLT]", vbTextCompare) > 0 Then
        '[CACCBUYRSLT][IP][PORT][NAME]
        tempIPAddress = Trim(processData(dataReceived))
        tempPortNo = Int(processData(dataReceived))
        tempPlayerName = Trim(processData(dataReceived))
        resetScreen
        If (tempIPAddress = localIPAddress And tempPortNo = localPort And tempPlayerName = playerName) Then
            upperbound = UBound(transactionList, 1)
            ReDim Preserve transactionList(upperbound + 1) As Variant
            transactionList(upperbound) = Array(offerUnit, offerPrice, "SELL")
            myUnit = myUnit - offerUnit
            myMoney = myMoney + (offerPrice * offerUnit)
            updateListBox ("You SUCESSFULLY sell")
           
            Set recTransaction = dbMydb.OpenRecordset("transaction", dbOpenTable)
            recTransaction.AddNew
            recTransaction("Quantity") = offerUnit
            recTransaction("Price") = offerPrice
            recTransaction("Transaction") = "SELL"
            recTransaction("Cost") = offerPrice * offerUnit
            recTransaction.Update
            recTransaction.Close
        Else
            updateListBox ("You FAILED to sell")
            updateListBox ("Sell to success for " + tempPlayerName + " at " + tempIPAddress + "," + CStr(tempPortNo))
        End If
        checkStatus
    ElseIf InStr(1, dataReceived, "[RESET]", vbTextCompare) > 0 Then
        'No one respond to server's offer. Server reset the offer
        updateListBox ("No one respond. Server reset transaction")
        resetScreen
        'MsgBox "No one respond to server. Offer reset"
    ElseIf InStr(1, dataReceived, "[END]", vbTextCompare) > 0 Then
        updateListBox ("Server terminate market transaction. Game over!")
        serverCloseEvent
        resetScreen
        mnConnect.Enabled = True
        mnDisconnect.Enabled = False
        cmdTransaction.Enabled = True
    End If
    updateStatus
Exit Sub
errorHandler:
    If (udpPeer.State > 0) Then
        udpPeer.Close
    End If
    mnConnect.Enabled = True
    mnDisconnect.Enabled = False
    Warn Err.Description
End Sub


Function resetGame()
    Dim clientInfo(1 To 3) As Variant
    transactionList = Array(clientInfo)
   
    lblPlayer.Caption = "Name: N/A"
    lblLocalHost.Caption = "Local IP/Host: " + localIPAddress
    lblLocalPort.Caption = "Local Port: N/A"
   
    lblRemoteHost.Caption = "Remote Host: N/A"
    lblRemotePort.Caption = "Remote Port: N/A"
   
    lblMyMoney.Caption = "$$ Left: $10, 000"
    lblUnit.Caption = "Unit onhand: 0"
   
    mnConnect.Enabled = True
    mnDisconnect.Enabled = False
   
    totalUnitAvail = 1000
    myMoney = 10000
    cmdTransaction.Enabled = False
End Function

Function updateStatus()
    lblPlayer.Caption = "Name: " + playerName
    lblLocalHost.Caption = "Local IP/Host: " + localIPAddress
    lblLocalPort.Caption = "Local Port: " + CStr(localPort)
   
    lblRemoteHost.Caption = "Remote Host: " + serverIP
    lblRemotePort.Caption = "Remote Port: " + CStr(serverPort)
   
    lblMyMoney.Caption = "$$ Left: $" + CStr(myMoney)
    lblUnit.Caption = "Unit onhand: " + CStr(myUnit)
End Function

Function resetScreen()
    lblMode.Caption = ""
    lblOfferUnit.Caption = ""
    lblPrice.Caption = ""
    lblMoneyNeeded.Caption = ""
    serverIP = ""
   
    cmdAccept.Enabled = False
    cmdCancel.Enabled = False
End Function

Function checkStatus()
    If (myUnit <= 0 And myMoney <= 0) Then
        MsgBox "You are loser"
    End If
End Function

Function updateListBox(ByVal tempstring As String)
    lstStatus.AddItem tempstring
    lstStatus.ListIndex = lstStatus.ListCount - 1
End Function

Function closeConnection()
    If (udpPeer.State > 0) Then
        udpPeer.SendData "[CLOSE][" & localIPAddress & "][" & CStr(localPort) & "][" & playerName & "]"
        udpPeer.Close
        updateListBox ("Disconnected from server")
        resetGame
    End If
End Function

Function serverCloseEvent()
    cmdTransaction.Enabled = True
    If (udpPeer.State > 0) Then
        udpPeer.Close
        updateListBox ("Connection to server lost. Game stopped.")
    End If
End Function






SERVER

Public serverPort As Integer
Public partNo As String
Public maxUnit As Integer
Public maxMoney As Integer
Public priceDiff As Integer
Public basePrice As Currency
Public connectionNo As Integer
Public randomPrice As Currency
Public randomUnit As Integer
Public sellMode As Boolean
Public inTransaction As Boolean
Public unitAvail As Integer
Public revenue As Currency
Public dbLocation As String
Public dbMydb As Database

Public connectionList
Public buyList
Public sellList


Private Sub cmdBuy_Click()
    frmBuy.Show vbModal
End Sub

Private Sub cmdSell_Click()
    frmSell.Show vbModal
End Sub

Private Sub cmdStart_Click()
    cmdStart.Enabled = False
    resetGame
    updateStatus
End Sub

Private Sub cmdStop_Click()
On Error GoTo errorHandler
    Dim upperbound As Integer
    Dim finishMsg As String
    Dim i As Integer
   
    tenderTimer.Enabled = False
    offerTimer.Enabled = False
    cmdStop.Enabled = False
    cmdStart.Enabled = True
    cmdBuy.Enabled = True
    cmdSell.Enabled = True
   
    connectionNo = 0
   
    upperbound = UBound(connectionList, 1)
    finishMsg = "Server terminate market transaction. Game over!"
    updateListBox (finishMsg)
       
    For i = upperbound - 1 To 0 Step -1
        If (connectionList(i)(3) = "A") Then
            udpPeer.remoteHost = CStr(connectionList(i)(0))
            udpPeer.remotePort = Int(connectionList(i)(1))
            udpPeer.SendData "[END]"
        End If
    Next i
    updateStatus
Exit Sub
errorHandler:
    'In case destination host has turn off the connection
End Sub

Private Sub Form_Load()
On Error GoTo errorHandler
    dbLocation = App.Path + "\server.mdb"
    Set dbMydb = OpenDatabase(dbLocation)
   
    partNo = "PINK"
    maxUnit = 1000
    maxMoney = 10000
    priceDiff = 50
    basePrice = 10
    serverPort = 7172
   
    'Running Server listening at Port 7172
    udpPeer.Bind serverPort
               
    resetGame
    updateStatus
Exit Sub
errorHandler:
    Warn ("Fail running server")
    MsgBox Err.Description
    End
End Sub


Private Sub Form_Unload(Cancel As Integer)
On Error GoTo errorHandler
    Dim ans As String
    If (connectionNo > 0) Then
        ans = MsgBox("There are " + CStr(connectionNo) + " users connected, are you sure you want to exit?", vbYesNo, "Exit")
        If ans = vbNo Then
            Cancel = 1
        Else
            dbMydb.Close
            upperbound = UBound(connectionList, 1)
            For i = upperbound - 1 To 0 Step -1
                If (connectionList(i)(3) = "A") Then
                    udpPeer.remoteHost = CStr(connectionList(i)(0))
                    udpPeer.remotePort = Int(connectionList(i)(1))
                    udpPeer.SendData "[END]"
                End If
            Next i
            udpPeer.Close
        End If
    Else
        udpPeer.Close
    End If
Exit Sub
errorHandler:
    'In case destination host has turn off the connection
End Sub


Private Sub offerTimer_Timer()
    offerTimer.Enabled = False
    Call generateEvent
End Sub

Private Sub tenderTimer_Timer()
On Error GoTo errorHandler
    'Means no one respond to the offer
    tenderTimer.Enabled = False
   
    Dim upperbound As Integer
    Dim i As Integer
    upperbound = UBound(connectionList, 1)
       
    updateListBox ("No one respond. Server reset transaction")
   
    For i = upperbound - 1 To 0 Step -1
        If (connectionList(i)(3) = "A") Then
            udpPeer.remoteHost = CStr(connectionList(i)(0))
            udpPeer.remotePort = Int(connectionList(i)(1))
            udpPeer.SendData "[RESET]" + invitationData
        End If
    Next i
   
    generateDelay
Exit Sub
errorHandler:
    'In case destination host has turn off the connection
End Sub


End Sub

Private Sub udpPeer_DataArrival(ByVal bytesTotal As Long)
'On Error GoTo errorHandler
    Dim dataReceived As String
    Dim remoteHost As String
    Dim playerName As String
    Dim remotePort As String
    Dim upperbound As Integer
   
   
    udpPeer.GetData dataReceived
   
    If InStr(1, dataReceived, "[CONNECT]", vbTextCompare) > 0 Then
        '[CONNECT][remoteHost][remotPort][playerName]
        remoteHost = processData(dataReceived)
        remotePort = processData(dataReceived)
        playerName = processData(dataReceived)
       
        udpPeer.remoteHost = remoteHost
        udpPeer.remotePort = Int(remotePort)
        udpPeer.SendData "[CONNECTOK]"
     
        updateListBox (playerName + " from " + remoteHost + " has connected to server")
        upperbound = UBound(connectionList, 1)
        ReDim Preserve connectionList(upperbound + 1) As Variant
       
        Dim tempArray(6) As String
        tempArray(0) = remoteHost
        tempArray(1) = remotePort
        tempArray(2) = playerName
        tempArray(3) = "A"
        tempArray(4) = "0"
        tempArray(5) = CStr(maxMoney)
       
        connectionList(upperbound) = tempArray()
       
        connectionNo = connectionNo + 1
        If (connectionNo > 1) Then 'Start the game when more than players joined the game
            cmdStop.Enabled = True
            Call generateEvent
        End If
    ElseIf InStr(1, dataReceived, "[CACCSELL]", vbTextCompare) > 0 Then
        '[CACCSELL][IP][Port][Name] Client accept to buy from server selling
        tenderTimer.Enabled = False
       
        remoteHost = processData(dataReceived)
        remotePort = processData(dataReceived)
        playerName = processData(dataReceived)
        updateListBox (playerName + " from " + remoteHost + " accept to BUY from server")
       
        Call commitTrans(remoteHost, remotePort, playerName, "CACCSELL")
       
        'If (unitAvail > 0) Then
            generateDelay
        'End If
       
    ElseIf InStr(1, dataReceived, "[CACCBUY]", vbTextCompare) > 0 Then
        '[CACCSELL][IP][Port][Name] Client accept to sell to server
        tenderTimer.Enabled = False
       
        remoteHost = processData(dataReceived)
        remotePort = processData(dataReceived)
        playerName = processData(dataReceived)
        updateListBox (playerName + " from " + remoteHost + " accept to SELL to server")
       
        Call commitTrans(remoteHost, remotePort, playerName, "CACCBUY")
       
        'If (unitAvail > 0) Then
            generateDelay
        'End If
   
    ElseIf InStr(1, dataReceived, "[CLOSE]", vbTextCompare) > 0 Then
        '"[CLOSE][IP][Port][PlayerName]"
        remoteHost = processData(dataReceived)
        remotePort = processData(dataReceived)
        Call removePlayer(remoteHost, remotePort)
    End If
    updateStatus
   
Exit Sub
errorHandler:
    Warn Err.Description
    'In case destination host has turn off the connection, skip data sending
End Sub

Function updateStatus()
    statusBar.Panels(1).Text = "Server listening at Port " + Str(serverPort) + "- " + Str(connectionNo) + " Connections"
    lblRevenue.Caption = CStr(Format(revenue, "###0.00"))
    lblUnit.Caption = CStr(unitAvail)
End Function

Private Sub generateEvent()
On Error GoTo errorHandler
    Dim strRandomPrice As String
    Dim randomValue As Integer
    Dim randomUnitSeed As Integer
    Dim invitationData As String
    Dim upperbound As Integer
   
    Randomize
    randomValue = (Int((51) * Rnd)) 'Random generate a number in between 0 and 50
   
    'To enable the price can be send to client for conversion back to float format
    'strRandomPrice = CStr(basePrice) + CStr(randomValue)
    'If (Len(strRandomPrice) <= 3) Then
    '    strRandomPrice = strRandomPrice + "0"
    'End If
   
    'Generate random price
    randomPrice = randomValue / 100
    randomPrice = basePrice + randomPrice
   
    strRandomPrice = CStr(randomPrice * 100)
   
    'Generate Sell/Buy mode
    If ((randomValue Mod 2 = 0 And unitAvail > 0) Or unitAvail = maxUnit) Then
        sellMode = True
        randomUnitSeed = unitAvail
    Else
        sellMode = False
        'randomUnitSeed = maxUnit - unitAvail
        randomUnitSeed = unitAvail
    End If

    If (randomUnitSeed > 120) Then
        Randomize
        randomUnit = Int((20 * Rnd) + 101) 'Random generate unit left/sold
    Else
        Randomize
        randomUnit = Int((randomUnitSeed * Rnd) + 1) 'Random generate unit left/sold
    End If
   
    invitationData = "[" + CStr(randomUnit) + "][" + strRandomPrice + "]"
   
    upperbound = UBound(connectionList, 1)
    If (sellMode) Then
        updateListBox ("Server wish to SELL " + CStr(randomUnit) + " units of PINK at $" + CStr(randomPrice))
    Else
        updateListBox ("Server wish to BUY " + CStr(randomUnit) + " units of PINK at $" + CStr(randomPrice))
    End If
       
    Dim i As Integer
    For i = upperbound - 1 To 0 Step -1
        If (connectionList(i)(3) = "A") Then
            udpPeer.remoteHost = CStr(connectionList(i)(0))
            udpPeer.remotePort = Int(connectionList(i)(1))
            If (sellMode) Then
                udpPeer.SendData "[SELL]" + invitationData
            Else
                udpPeer.SendData "[BUY]" + invitationData
            End If
        End If
    Next i
    tenderTimer.Interval = 10000
    tenderTimer.Enabled = True
Exit Sub
errorHandler:
    'In case destination host has turn off the connection
End Sub

'Function getSoldQty() As Integer
    'Dim tempQty As Integer
    'tempQty = 0
    'For I = connectionNo - 1 To 0 Step -1
        'tempQty = tempQty + connectionList(I)(3)
    'Next I
    'getSoldQty = tempQty
'End Function

Function resetGame()
    'offerTimer.Enabled = True
    Dim clientInfo(1 To 4) As Variant
    Dim masterInfo(1 To 6) As Variant
   
    'Cell 0 storing Remote IP
    'Cell 1 storing Remote Port
    'Cell 2 storing player name
    'Cell 3 storing player state
    'Cell 4 storing player's onhand qty
    'Cell 5 storing player's money
   
    inTransaction = False
    connectionList = Array(masterInfo)
    buyList = Array(clientInfo)
    sellList = Array(clientInfo)

    connectionNo = 0
    unitAvail = maxUnit
    revenue = 0
   
    lblUnit.Caption = CStr(unitAvail)
    lblRevenue = CStr(Format(revenue, "###0.00"))
    lstStatus.Clear
    cmdBuy.Enabled = False
    cmdSell.Enabled = False
End Function

Private Sub commitTrans(ByVal IP As String, ByVal remotePort As Integer, ByVal remotePlayer As String, ByVal transMode As String)
On Error GoTo errorHandler
    Dim upperbound As Integer
    Dim tempArray(4) As String
    Dim tempMoney As Currency
    Dim tempQty As Integer
    Dim recTransaction As Recordset
   
    inTransaction = True
    If (transMode = "CACCSELL") Then
        'Client accept to buy from server selling
        unitAvail = unitAvail - randomUnit
        revenue = revenue + (randomUnit * randomPrice)
       
        upperbound = UBound(sellList, 1)
        ReDim Preserve sellList(upperbound + 1) As Variant
       
        tempArray(0) = IP
        tempArray(1) = CStr(remotePort)
        tempArray(2) = CStr(randomUnit)
        tempArray(3) = CStr(randomPrice)
        sellList(upperbound) = tempArray()
       
        upperbound = UBound(connectionList, 1)
        updateListBox ("SOLD to " + remotePlayer + " at " + IP)
       
        Set recTransaction = dbMydb.OpenRecordset("transaction", dbOpenTable)
        recTransaction.AddNew
        recTransaction("IP") = IP
        recTransaction("Port") = remotePort
        recTransaction("Quantity") = randomUnit
        recTransaction("Price") = randomPrice
        recTransaction("Transaction") = "SELL"
        recTransaction.Update
        recTransaction.Close
       
        For i = upperbound - 1 To 0 Step -1
            If (connectionList(i)(3) = "A") Then
                'Update player money and onhand quantity information
                If (connectionList(i)(0) = IP And connectionList(i)(1) = remotePort) Then
                    connectionList(i)(4) = CStr(CInt(connectionList(i)(4)) + randomUnit)
                    connectionList(i)(5) = CStr(CCur(connectionList(i)(5) - (randomUnit * randomPrice)))
                End If
               
                udpPeer.remoteHost = CStr(connectionList(i)(0))
                udpPeer.remotePort = Int(connectionList(i)(1))
                udpPeer.SendData "[CACCSELLRSLT][" + IP + "][" + CStr(remotePort) + "][" + remotePlayer + "]"
            End If
        Next i
    ElseIf (transMode = "CACCBUY") Then
        'Client accept to sell to server buying
        unitAvail = unitAvail + randomUnit
        revenue = revenue - (randomUnit * randomPrice)
       
        upperbound = UBound(buyList, 1)
        ReDim Preserve buyList(upperbound + 1) As Variant
       
        tempArray(0) = IP
        tempArray(1) = CStr(remotePort)
        tempArray(2) = CStr(randomUnit)
        tempArray(3) = CStr(randomPrice)
        buyList(upperbound) = tempArray()
       
        upperbound = UBound(connectionList, 1)
        updateListBox ("BUY from " + remotePlayer + " at " + IP)
       
        Set recTransaction = dbMydb.OpenRecordset("transaction", dbOpenTable)
        recTransaction.AddNew
        recTransaction("IP") = IP
        recTransaction("Port") = remotePort
        recTransaction("Quantity") = randomUnit
        recTransaction("Price") = randomPrice
        recTransaction("Transaction") = "BUY"
        recTransaction.Update
        recTransaction.Close
       
        For i = upperbound - 1 To 0 Step -1
            If (connectionList(i)(3) = "A") Then
                If (connectionList(i)(0) = IP And connectionList(i)(1) = remotePort) Then
                    connectionList(i)(4) = CStr(CInt(connectionList(i)(4)) - randomUnit)
                    connectionList(i)(5) = CStr(CCur(connectionList(i)(5) + (randomUnit * randomPrice)))
                End If
               
                udpPeer.remoteHost = CStr(connectionList(i)(0))
                udpPeer.remotePort = Int(connectionList(i)(1))
                udpPeer.SendData "[CACCBUYRSLT][" + IP + "][" + CStr(remotePort) + "][" + remotePlayer + "]"
            End If
        Next i
    End If
    inTransaction = False
    updateStatus
Exit Sub
errorHandler:
    'In case destination host has turn off the connection
End Sub

Function generateDelay()
    Dim randomValue As Integer
    If (unitAvail > 0) Then
        Randomize
        randomValue = (Int((10) * Rnd) + 1) 'Random generate a number in between 0 and 50
        randomValue = randomValue * 1000
        offerTimer.Interval = randomValue
        offerTimer.Enabled = True
    Else
        updateStatus
        updateListBox ("All unit sold out. Game stops.")
        Call cmdStop_Click
    End If
End Function

Function updateListBox(ByVal tempstring As String)
    lstStatus.AddItem tempstring
    lstStatus.ListIndex = lstStatus.ListCount - 1
End Function

Function removePlayer(ByVal remoteHost As String, ByVal remotePort As String)
    Dim upperbound As Integer
    Dim tempPlayer As String
   
    upperbound = UBound(connectionList, 1)
   
    For i = upperbound - 1 To 0 Step -1
        If (connectionList(i)(0) = remoteHost And connectionList(i)(1) = remotePort) Then
            connectionList(i)(3) = "D"
            tempPlayer = connectionList(i)(2)
            i = 0
        End If
    Next i
    updateListBox (tempPlayer + " at " + remoteHost + " has being disconnected")
    connectionNo = connectionNo - 1
    updateStatus
End Function



0
Comment
Question by:belim
6 Comments
 
LVL 22

Expert Comment

by:mnasman
ID: 6957359
0
 
LVL 3

Accepted Solution

by:
adg earned 200 total points
ID: 6957365
I asked the same question last December.  Just disregard the error and all's well. It happens prior to the connection being made but it doesn't prevent the connection.

ErrorHandler:
   If Err.Number = 126 Then
      Resume Next
   End If  
0
 
LVL 3

Expert Comment

by:adg
ID: 6957372
Also I just noticed that you have 5 questions from 2001 unresolved.  You should either award the points by accepting an answer or post in the community support topic to get your points refunded.   If you need help, just ask.

Thanks!
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6957457
SInce it is a winsock question, could do i a ping...?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660607
Hi belim,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept adg@hp's comment(s) as an answer.

belim, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7755178
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now